Transition in Corona SDK

青春壹個敷衍的年華 提交于 2019-12-06 03:33:20

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

Color is not supported in Corona's transition API at the moment. You might try to use...

show_text:setTextColor( red, green, blue )

...inside a loop and just draw and erase the text object as you alter the color values.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!