I know that you can setFillColor of an object. In my app i have objects that when created generate a random fill color. Later in my app I am wanting to retrieve the RGB value of those objects to compare and use in my code… any ides of how i could achieve this? thanks! [import]uid: 19620 topic_id: 22318 reply_id: 322318[/import]
First create a table of colors:
[lua]local colors = {
{255,0,0},
{0,0,255},
{0,255,0},
{255, 255, 0},
{255,0,255}
}[/lua]
Then when you create your rectangle, make it look like this:
[lua]local rect = display.newRect(0, 0,100,100)
rect.color = math.random(1,5)
rect:setFillColor(unpack(colors[rect.color]))[/lua]
Hope this helps.
Regards,
Jordan Schuetz
Ninja Pig Studios [import]uid: 29181 topic_id: 22318 reply_id: 88916[/import]
In lua, you can add properties to objects just by setting a value.
so you can do this:
[code]
local rect = display.newRect(0, 0,100,100)
rect.r = math.random(0,255) --new value which didn’t exist before now…
rect.g = math.random(0,255)
rect.b = math.random(0,255)
rect:setFillColor(rect.r,rect.g,rect.b)
–what is it?
print (rect.r,rect.g,rect.b)
[/code] [import]uid: 108660 topic_id: 22318 reply_id: 88924[/import]
Brilliant, easy enough. Thanks for the idea on how to do that. [import]uid: 19620 topic_id: 22318 reply_id: 88959[/import]