我希望我没有错过任何非常明显的事情。我试图了解以下行为。
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
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
local fileOne = require "fileOne" ()
local fileTwo = require "fileTwo" ()
fileOne:start()
fileTwo:stop()
当我编译它时,动画不起作用。第二个文件中的停止功能会停止第一个文件中的动画。我对命名空间有些问题吗?或其他一些参考问题?或语法问题?
答案 0 :(得分:0)
致电时
fileTwo:stop();
您正在调用transition.cancel( null )
,并且似乎使用null调用此函数会导致奇怪的行为。
如果你把它放在fileTwo
上if(self.AnimationTransition ~= nil) then
transition.cancel( self.AnimationTransition )
end
问题已经消失。