Im trying to create a display.circle and then have the color of the circle transition from red to blue back and forth. I havent really come up with any code that works. Was wondering if anyone had any ideas? I think I could do it if the transition.to included the setFillColor rgb values, but I dont believe it does? [import]uid: 28912 topic_id: 34348 reply_id: 334348[/import]
Take a look at the sample video on this blog post:
http://insidecoronasdk.com/corona-sdk/challenge-status-2/
I could select a part of the picture and then set the color to change and it would do that over time.
The magic? Just a timer to call a tweakColor() function every 100 ms that changed the desired color and did a setFillColor() on the pic.
Would be nice if transition.to() allowed setFillColor(), but doing it with a timer should work for you.
Jay [import]uid: 9440 topic_id: 34348 reply_id: 136542[/import]
And, if you play around with that, I just looked at my code and saw that after the setFillColor() call I had to do this:
[lua] obj:translate( .1,0 )
obj:translate( -.1,0 )[/lua]
Not sure whether that’s a bug that’s been fixed since then or not. If I remember correctly, I had to move the pic I was changing and then move it back to get the color change to show up.
Just something to know in case you don’t get the results you think you should. 
Jay [import]uid: 9440 topic_id: 34348 reply_id: 136543[/import]
not pretty, sure its not the best way, but it works
local color = {r=255,g=0,b=0}
local cir = display.newCircle(160, 240, 100)
function cir:enterFrame()
cir:setFillColor(color.r, color.g, color.b)
end
function changeColor()
transition.to(color, { time = 5000, r = 0, b = 255 })
transition.to(color, {time = 5000, delay = 5000, r = 255, b = 0, onComplete = changeColor})
end
function cir:start()
Runtime:addEventListener("enterFrame", self)
changeColor()
end
cir:start()
or you can do this
[code]
local color, dir, speed = 0, 1, 3
local cir = display.newCircle(160, 240, 100)
function cirColor()
if color > 254 then
dir = -1
elseif color < 1 then
dir = 1
end
color = color + (speed*dir)
cir:setFillColor(255 - color, 0, color)
end
Runtime:addEventListener(“enterFrame”, cirColor)
[import]uid: 7911 topic_id: 34348 reply_id: 136544[/import]
@Whye I played around with that a little bit, and I think the object might still need to be translated as you said. Couldnt get it to work too well.
@jstrahan I got your code to work, transitions nicely from red to blue, or can change it to
if bullet.color \> 1 or bullet.color \< 254 then
bullet.dir = -bullet.dir
end
bullet.color = bullet.color + (bullet.speed\*bullet.dir)
bullet:setFillColor(255 - bullet.color, 0, bullet.color)
for an instant transition.
Either way, I have lots of flashing circles on my screen now!
[import]uid: 28912 topic_id: 34348 reply_id: 136548[/import]
glad it worked [import]uid: 7911 topic_id: 34348 reply_id: 136549[/import]
Hey, check this out:
http://developer.coronalabs.com/code/color-transition-wrapper [import]uid: 147322 topic_id: 34348 reply_id: 136590[/import]
Take a look at the sample video on this blog post:
http://insidecoronasdk.com/corona-sdk/challenge-status-2/
I could select a part of the picture and then set the color to change and it would do that over time.
The magic? Just a timer to call a tweakColor() function every 100 ms that changed the desired color and did a setFillColor() on the pic.
Would be nice if transition.to() allowed setFillColor(), but doing it with a timer should work for you.
Jay [import]uid: 9440 topic_id: 34348 reply_id: 136542[/import]
And, if you play around with that, I just looked at my code and saw that after the setFillColor() call I had to do this:
[lua] obj:translate( .1,0 )
obj:translate( -.1,0 )[/lua]
Not sure whether that’s a bug that’s been fixed since then or not. If I remember correctly, I had to move the pic I was changing and then move it back to get the color change to show up.
Just something to know in case you don’t get the results you think you should. 
Jay [import]uid: 9440 topic_id: 34348 reply_id: 136543[/import]
not pretty, sure its not the best way, but it works
local color = {r=255,g=0,b=0}
local cir = display.newCircle(160, 240, 100)
function cir:enterFrame()
cir:setFillColor(color.r, color.g, color.b)
end
function changeColor()
transition.to(color, { time = 5000, r = 0, b = 255 })
transition.to(color, {time = 5000, delay = 5000, r = 255, b = 0, onComplete = changeColor})
end
function cir:start()
Runtime:addEventListener("enterFrame", self)
changeColor()
end
cir:start()
or you can do this
[code]
local color, dir, speed = 0, 1, 3
local cir = display.newCircle(160, 240, 100)
function cirColor()
if color > 254 then
dir = -1
elseif color < 1 then
dir = 1
end
color = color + (speed*dir)
cir:setFillColor(255 - color, 0, color)
end
Runtime:addEventListener(“enterFrame”, cirColor)
[import]uid: 7911 topic_id: 34348 reply_id: 136544[/import]
@Whye I played around with that a little bit, and I think the object might still need to be translated as you said. Couldnt get it to work too well.
@jstrahan I got your code to work, transitions nicely from red to blue, or can change it to
if bullet.color \> 1 or bullet.color \< 254 then
bullet.dir = -bullet.dir
end
bullet.color = bullet.color + (bullet.speed\*bullet.dir)
bullet:setFillColor(255 - bullet.color, 0, bullet.color)
for an instant transition.
Either way, I have lots of flashing circles on my screen now!
[import]uid: 28912 topic_id: 34348 reply_id: 136548[/import]
glad it worked [import]uid: 7911 topic_id: 34348 reply_id: 136549[/import]
Hey, check this out:
http://developer.coronalabs.com/code/color-transition-wrapper [import]uid: 147322 topic_id: 34348 reply_id: 136590[/import]