简体   繁体   中英

Corona SDK Strange transition behaviour

I hope I did not miss something very obvious. I am trying to understand the following behaviour.


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

When I compile this, the animation does not work. The stop function from the second file stops the animation from the first file. Do I have some problem with the namespace? or some other referencing problem? or syntax problem?

When you call

fileTwo:stop();

You are calling transition.cancel( null ) , and it seems calling this function with null cause strange behaviours.

If you put this, on fileTwo

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

Problem is gone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM