ymobe/rapanui — Issue #22: Editing vector shape colour after creation.
Author: anddrewscott
Created: 2012-02-19 19:25:31+00:00
State: open

I do not understand the use of the colon, but here is the function (without the colon):

local square = RNFactory.createRect(0,0,50,50)
local circle = RNFactory.createCircle(200, 50, 25)
square.shape = "rect" -- put in RNObject when object is first made (or some other way)
circle.shape = "circle"

setColour = function(self,r,g,b)
local function onDraw()
MOAIGfxDevice.setPenColor(r * 0.00392, g * 0.00392, b * 0.00392, 1)--self.alpha)
if self.shape == "rect" then
MOAIDraw.fillRect(0,0,self.originalWidth,self.originalHeight)
else
MOAIDraw.fillCircle(0, 0, self.originalWidth*.5, 32)
end
end
self.gfxQuad:setDrawCallback(onDraw)
end

setColour(square, 255, 0 ,0)
setColour(circle, 255, 0 ,0)