Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Help! Why Doesn't This Work? (setColorTransform) — Gideros Forum

Help! Why Doesn't This Work? (setColorTransform)

jaywatjaywat Member
edited March 2012 in General questions
Can someone tell me why this for loop code doesn't make a visible color transform?
local uiX = 10
local uiY = 10
 
colors = {
	{50,100,150},
	{150,100,50},
	{100,100,100}
}
 
for i = 1, #colors do	
	local thisImage = Bitmap.new(Texture.new("ball.png"))
	thisImage:setColorTransform(colors[i][1], colors[i][2], colors[i][3],1)
	thisImage:setPosition(uiX, uiY)
	stage:addChild(thisImage)
	uiX = uiX + 50
	print (thisImage:getColorTransform())
end
The print statement correctly returns:

50 100 150 1
150 100 50 1
100 100 100 1

So... why am I not seeing any transform? I should get 3 visibly different colors, but they're just white.

The thing is, if I tell it to setColorTransform(colors[i][1], 0, 0,1), I get a red... but ALL of the sprites appear to be the same red, when they ought to be visibly different.

Is there some problem with trying to set a color transform on all 3 color channels in a loop? or am I doing something dumb?
+1 -1 (+7 / -0 )Share on Facebook

Comments

  • um. Actually... I could have shortened that considerably to the following:

    why doesn't THIS work? It's nothing to do with loops... setting color transform with 3 specified channels that aren't 'all or nothing' values simply isn't showing a result:
    	local thisImage = Bitmap.new(Texture.new("ball.png"))
    	stage:addChild(thisImage)
    	thisImage:setColorTransform(150, 100, 50,1)
  • ar2rsawseenar2rsawseen Maintainer
    edited March 2012
    If they are all white, it could explain it. Because in docs it is stated that you are passing multipliers, not colors themselves. As your multipliers are high, then color value multiplied by your multiplier provides maximal value - which is 255, hence white color.

    I'd suggest experimenting with lower values. :)
  • oh. i see. So you're not passing in rgb values. You're expected to pass in values between 0 and 1. Well that would explain that! Thanks :)

    Gideros does some things in odd ways! (Like, why are some colors expressed in hex and others in rgb, and why is rgb between 0 and 1?!)
  • evsevs Member
    Hello,

    Instead of using Sprite:setColorTransform(redMultiplier, greenMultiplier, blueMultiplier, alphaMultiplier)

    you can use Sprite:setColorTransform(red / 255, green / 255, blue /255, alpha / 255)

    if you're used to rgba


    cheers

    evs
  • atilimatilim Maintainer
    @jaywat But as ar2rsawseen said they are color multipliers. Therefore, they are between [0, 1]. In Gideros, other color values are expressed always in hexadecimal format.
Sign In or Register to comment.