更新时间:2023-02-26 20:39:10
下面的技巧的作品。不幸的是它不允许非常复杂的颜色的处理,而无需使用多个过渡
本地函数修改(文本)
本地MT = {
R = 0,
G = 0,
B = 0,
__index =功能(T,K)
如果k ==R或k ==G或k ==B,那么
返回getmetatable(T)[K]
结束
结束,
__newindex =功能(T,K,V)
getmetatable(t)的[K] = V
如果k ==R或k ==G或k ==B,那么
T:setTextColor(math.round(T.R或0),math.round(T.G或0),math.round(t.b或0))
结束
结束
}
当地originalSetTextColor = text.setTextColor
text.setTextColor =功能(自我,R,G,B)
mt.r = R
mt.g = G
mt.b = B
originalSetTextColor(自我,R,G,B)
结束
setmetatable(文字,MT)结束当地show_text = display.newEmbossedText(我的典范的现代化大将军,display.screenOriginX,0,native.systemFont,30);
修改(show_text)
show_text:setTextColor(255,0,255)transition.to(show_text,{时间= 1000,R = 0,})
transition.to(show_text,{时间= 1000,G = 255})
transition.to(show_text,{时间= 1000,B = 0})
How to give transition for changing color in corona sdk.
I have tried like this, but it's not working
transition.to (show_text, {time=1000,color="rgb(0,0,0)"});
The following trick works. Unfortunately it doesn't allow for very sophisticated color manipulations without using multiple transitions:
local function modify(text)
local mt = {
r = 0,
g = 0,
b = 0,
__index = function(t, k)
if k == "r" or k == "g" or k == "b" then
return getmetatable(t)[k]
end
end,
__newindex = function(t, k, v)
getmetatable(t)[k] = v
if k == "r" or k == "g" or k == "b" then
t:setTextColor(math.round(t.r or 0), math.round(t.g or 0), math.round(t.b or 0))
end
end
}
local originalSetTextColor = text.setTextColor
text.setTextColor = function(self,r,g,b)
mt.r = r
mt.g = g
mt.b = b
originalSetTextColor(self, r,g,b)
end
setmetatable(text, mt)
end
local show_text = display.newEmbossedText("I am the very model of a modern major general", display.screenOriginX,0, native.systemFont, 30);
modify(show_text)
show_text:setTextColor(255,0,255)
transition.to (show_text, {time=1000,r=0,})
transition.to (show_text, {time=1000,g=255})
transition.to (show_text, {time=1000,b=0})