我正在尝试以下链接中的 GTween 示例
该示例无法开箱即用,因此我深入研究了 GTween 的源代码,并将以下几行添加到我的示例中以允许事件调度。
local tween = GTween.new(jewel, 2, animProperties, gtweenProperties)
tween.suppressEvents = false -- New Line #1
tween.dispatchEvents = true -- New Line #2
tween:addEventListener('complete', function()
stage:removeChild(jewel)
jewel = nil
end)
但是,应用程序崩溃了。我尝试在 gtween.lua
self:dispatchEvent(Event.new(name))
应用程序不会崩溃,但是不会调用回调(显然,为什么会崩溃?)
这是应用程序的堆栈跟踪。
gtween.lua:445: attempt to call method 'dispatchEvent' (a boolean value)
stack traceback:
gtween.lua:445: in function 'dispatchEvt'
gtween.lua:255: in function 'setPosition'
gtween.lua:86: in function <gtween.lua:74>
任何指示将不胜感激。谢谢。
PS:我不确定这是否是 Gideros 上的错误。
最佳答案
我刚刚尝试了最新的 gideros' gtween (请注意,它是 10 天前编辑的),并使用此示例(我从您的链接中获取了示例并添加了 Sprite 定义,还包括项目中的图像文件)并且它有效(调用了回调):
local animate = {}
animate.y = 100
animate.x = 100
animate.alpha = 0.5
animate.scaleX = 0.5
animate.scaleY = 0.5
animate.rotation = math.random(0, 360)
local properties = {}
properties.delay = 0
properties.ease = easing.inElastic
properties.dispatchEvents = true
local sprite = Bitmap.new(Texture.new("box.png")) -- ADD THIS
stage:addChild(sprite) -- ADD THIS
local tween = GTween.new(sprite, 10, animate, properties)
tween:addEventListener("complete", function()
stage:removeChild(sprite)
sprite = nil
end)
关于Gideros GTween 事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15942596/