I ran into a little issue just now and wondered if there was an easy way around it. Is it possible to copy a color object?
I have the following:
-- global variable
cLightBlue = color(0, 232, 216, 255)
-- in a class, elsewhere:
self.fillColor = cLightBlue
self.fillColor.a = 100
The problem is, this affects anything that uses the cLightBlue colour! So I presume self.fillColor is a reference to my global variable, rather than a copy of it.
Any way around this, or do I manually need to copy each property of the color or something?
Thanks all :)
I think you'll need to manually copy, like this:
self.fillColor = color( cLightBlue.r, cLightBlue.g, cLightBlue.b, cLightBlue.a )
An alternative would be to define you colour constant as a factory function:
cLightBlue = function() return color(0, 232, 216, 255) end
self.fillColor = cLightBlue()
Or define a colour-copy function
function cc(c)
return color(c.r,c.g,c.b,c.a)
end
self.fillColor = cc( cLightBlue )
It looks like you're new here. If you want to get involved, click one of these buttons!