2013-10-27 21 views
1

我可以更改文本字段的轉換顏色嗎? 我嘗試像這樣正常的轉換,但沒有奏效。Corona SDK - 我如何更改顏色文本與轉換?

explainer = display.newText("my text", 100,100,"Hiragino Maru Gothic Pro",30) 
transition.to(explainer, { time=100, color="rgba(255,0,0)" }) 
+1

[轉型的可能重複Corona SDK](http://stackoverflow.com/questions/8425725/transition-in-corona-sdk) – Kamiccolo

+0

哦是對不起... – Simonini

+0

不用擔心;)該線程沒有正確命名... – Kamiccolo

回答

1

你真的不能用transition.to做到這一點。您必須在enterFrame監聽器中執行此操作,並在每個步驟中增加R,G,B值。

1

這裏有一個代碼,讓你製作一個blink效果。您可以刪除改變增量的一部分,它會爲你工作:

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() 

在這種情況下,rowPlayerNamerowScore是2 display.newText需要改變在一起。

0

你也可以做的,是剛剛把另一對象在它與不同的顏色,然後使用transition.to方法改變其alpha設置爲0。這個對象阿爾法屬性設置爲1