TOUR
PRICING
HELP
Stencylpedia
Blocks Guide
Sample Games
Developer Center
FORUMS
CHAT
#MADEINSTENCYL
EDUCATION
SIGN IN
×
Welcome back!
Username or E-mail
Password
(
Forgot?
)
C
OMMUNITY
Home
Issue Tracker
Inbox [0]
New Posts
New Replies
Search
Stencyl Community
→
Stencyl
→
Ask a Question
→
random color
Pages:
1
random color
readerboy7
Posts: 59
October 11, 2011, 03:11:27 pm
i want a random color where red is 0, green is random number between 1 and 20, blue is a random number between 200 and 255. i know this is possible with code, but i don't know the code.
Alexin
Posts: 3127
October 11, 2011, 03:34:32 pm
Red
,
Green
and
Blue
are hidden Number attributes.
_RandomColor
is the internal name of a Color attribute. I created it as
Random Color
.
This is the code that goes inside the code block.
Code:
[Select]
_RandomColor = Util.RGBToHex(_Red, _Green, _Blue);
Use the four blocks in the picture whenever you want to randomize the color.
"Find the fun"
alexin@stencyl.com
readerboy7
Posts: 59
October 11, 2011, 08:17:23 pm
sorry. i tried it with this behavior [see attachment] but it didn't work.
apparently color,r,g and b are undefined.
coleislazy
Posts: 2607
October 12, 2011, 04:31:23 am
Make sure you're putting the underscore before the variables (_color, _r, etc). I can't tell if you are, since the single-line code block cuts off the bottom of the characters.
Alexin
Posts: 3127
October 12, 2011, 05:17:08 am
What coleislazy said. Also, you aren't using the random color anywhere in the behavior.
I uploaded a behavior to demonstrate the code. It's on Forge and named Draw Rect With Random Color.
It picks a totally random color to make the effect more apparent.
(The values you want to use barely affect the final color, which always looks pure blue.)
"Find the fun"
alexin@stencyl.com
aprotasenya
Posts: 10
June 22, 2013, 02:34:20 pm
Alexin,
Thanks a lot for this code! I thought it should be done in some numerical way, but had no chance to write the code myself. This is simple and yet works great!
Pages:
1