2013-04-11 225 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