【问题标题】:Corona SDK Strange transition behaviourCorona SDK 奇怪的过渡行为
【发布时间】:2015-01-15 11:18:38
【问题描述】:

我希望我没有错过一些非常明显的东西。我正在尝试理解以下行为。


fileOne.lua

return function()
local self = display.newGroup()

local text = display.newText({
    text = "TEXT ONE",
    x = 100,
    y = 100,
    fontSize = 20
})

self:insert(text)

function self:animate()
    local function scale(phase)
        if phase == "down" then
            self.AnimationTransition = transition.scaleTo( self, {xScale=0.95, yScale=0.95, time=500, onComplete=function() scale("up") end} )
        elseif phase == "up" then
            self.AnimationTransition = transition.scaleTo( self, {xScale=1.05, yScale=1.05, time=500, onComplete=function() scale("down") end} )
        end
    end
    scale("down")
end

function self:start()
    self:animate()
end

function self:stop()
    transition.cancel( self.AnimationTransition )
end

return self;
end

fileTwo.lua

return function()
local self = display.newGroup()

local text = display.newText({
    text = "TEXT TWO",
    x = 100,
    y = 100,
    fontSize = 20
})

self:insert(text)

function self:animate()
    local function scale(phase)
        if phase == "down" then
            self.AnimationTransition = transition.scaleTo( self, {xScale=0.95, yScale=0.95, time=500, onComplete=function() scale("up") end} )
        elseif phase == "up" then
            self.AnimationTransition = transition.scaleTo( self, {xScale=1.05, yScale=1.05, time=500, onComplete=function() scale("down") end} )
        end
    end
    scale("down")
end

function self:start()
    self:animate()
end

function self:stop()
    transition.cancel( self.AnimationTransition )
end

return self;
end

main.lua

local fileOne = require "fileOne" ()
local fileTwo = require "fileTwo" ()

fileOne:start()
fileTwo:stop()

当我编译这个时,动画不起作用。第二个文件中的停止函数会停止第一个文件中的动画。我的命名空间有问题吗?或其他一些参考问题?还是语法问题?

【问题讨论】:

    标签: lua coronasdk transitions


    【解决方案1】:

    当你打电话时

    fileTwo:stop();
    

    您正在调用 transition.cancel( null ),并且似乎以 null 调用此函数会导致奇怪的行为。

    如果你把这个放在fileTwo上

    if(self.AnimationTransition ~= nil) then
        transition.cancel( self.AnimationTransition )
    end
    

    问题消失了。

    【讨论】:

    • 啊,谢谢。我真的不明白为什么一切都还在工作。我在更大的背景下发现了这种行为,除此之外一切正常。在可能出现意外行为的情况下,我预计会出现一些错误或任何事情。
    猜你喜欢
    • 1970-01-01
    • 2017-03-05
    • 2012-11-28
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    • 1970-01-01
    相关资源
    最近更新 更多