2013-04-11 226 views
1

我想一个GTween例如,从下面的链接Gideros GTween事件监听器

Gideros GTween with Easing

的例子不工作开箱即用,所以我挖成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上的一个bug。

回答

1

我刚刚尝试过最新的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) 
+0

嗨,我试图通过复制的例子,它的工作,不知道为什么它没有工作过。谢谢你的时间。 – 2013-04-20 05:18:25