How can I get the colour (fill) of a DisplayObject in response to an event like a touch in Corona SDK? -
can me find out how can can color of rectangle in corona? rectangle filled color, want color when touch on rectangle.
create rectangle:
local rectangle = display.newrect(0, 0, 100, 100)
put color in rgba (you can leave out a) format in table, , store "custom property" rectangle:
rectangle.fillcolor = {110, 30, 25}
through magic of unpack function, returns values of table, pass table setfillcolor:
rectangle:setfillcolor( unpack(rectangle.fillcolor) )
now can color so:
print( unpack(rectangle.fillcolor) ) --> 110 30 25
or
print( rectangle.fillcolor ) -- returns table
or put each color in variable:
local red, green, blue, alpha = unpack(rectangle.fillcolor)
you'll see how can come in handy other things well.
edit
just thought of cool way of doing it, highjacking setfillcolor function:
local function decoraterectangle(rect) rect.cachedsetfillcolor = rect.setfillcolor -- store setfillcolor function function rect:setfillcolor(...) -- replace our own function self:cachedsetfillcolor(...) self.storedcolor = {...} -- store color end function rect:getfillcolor() return unpack(self.storedcolor) end end local rectangle = display.newrect(0, 0, 100, 100) decoraterectangle(rectangle) -- "decorates" rectangle more awesomeness
now can use setfillcolor set color normal, , getfillcolor return :)
rectangle:setfillcolor(100, 30, 255, 255) print(rectangle:getfillcolor())
Comments
Post a Comment