转型电晕SDK [英] Transition in Corona SDK

查看:143
本文介绍了转型电晕SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何给在电晕SDK改变颜色过渡。

我已经试过这样,但它不工作

  transition.to(show_text,{时间= 1000,颜色=RGB(0,0,0)});


解决方案

下面的技巧的作品。不幸的是它不允许非常复杂的颜色的处理,而无需使用多个过渡

 本地函数修改(文本)
    本地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})

这篇关于转型电晕SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆