Reputation: 623
Can i change color of text field with transition? I try with normal transition like this but did not work.
explainer = display.newText("my text", 100,100,"Hiragino Maru Gothic Pro",30)
transition.to(explainer, { time=100, color="rgba(255,0,0)" })
Upvotes: 1
Views: 2051
Reputation: 95
What you could also do, is just put another object over it with different color and set its alpha to 0. Then using transition.to method change this objects alpha property to 1.
Upvotes: 0
Reputation: 2137
Here's a code that let's you make a blink
effect. You can remove the part that changes the increment and it will work for you:
local min_r,min_g,min_b=100,100,255 -- Initial color
local max_r,max_g,max_b=255,255,255 -- End color
local color_steps=15 -- Adjust this to make it more fast/slow
local current_step=0
local increment=1
local step_r=(max_r-min_r)/color_steps
local step_g=(max_g-min_g)/color_steps
local step_b=(max_b-min_b)/color_steps
function blink()
if (rowPlayerName and rowPlayerName["text"] and rowScore and rowScore["text"]) then
rowPlayerName:setTextColor( min_r+current_step*step_r, min_g+current_step*step_g, min_b+current_step*step_b )
rowScore:setTextColor(min_r+current_step*step_r, min_g+current_step*step_g, min_b+current_step*step_b )
current_step=current_step+increment
if (current_step>=color_steps) then
current_step=color_steps-1
increment=-increment
elseif (current_step<0) then
current_step=0
increment=-increment
end
timer.performWithDelay(50, blink)
end
end
blink()
In this case, rowPlayerName
and rowScore
are 2 display.newText
that need to be changed together.
Upvotes: 1
Reputation: 3063
You really can't do this with transition.to. You would have to do it in an enterFrame listener and increment your R, G, B values during each step.
Upvotes: 1