2013-08-28 25 views
0

我剛剛開始使用EaselJS,並且正在進入我的第一個障礙。我已經擴展容器對象,以創建一個新類叫蛋:EaselJS打勾事件delta屬性未傳播給兒童

(function() { 

var Egg = function(color, x, y, cY) { 
    this.initialize(color, x, y, cY); 
} 
var e = Egg.prototype = new createjs.Container(); // inherit from Container 

e.Container_initialize = e.initialize; 
e.initialize = function(color, x, y, cY) { 

    this.Container_initialize(); 

    this.circle = new createjs.Shape(); 
    this.circle.graphics.beginFill(color).drawCircle(0, 0, 10); 
    this.circle.x = x; 
    this.circle.y = y; 
    this.addChild(this.circle); 

    this.changeY = cY; 

    this.addEventListener("tick", this.handleTick); 

} 

e.handleTick = function(event) { 
    console.log(event.delta); // undefined! 
} 

window.Egg = Egg; 

}()); 

而且我初始化這樣的:

var stage, timeCircle; 

function init() { 

    stage = new createjs.Stage("gameCanvas"); 

    timeCircle = new createjs.Shape(); 

    createjs.Ticker.useRAF = true; 
    createjs.Ticker.setFPS(30); 
    createjs.Ticker.addEventListener("tick", tick); 

    var egg = new Egg("red", 50, 50, 100); 
    stage.addChild(egg); 

    var egg2 = new Egg("blue", 100, 50, 50); 
    stage.addChild(egg2); 

} 


function tick(event) { 
    stage.update(event); 
} 

雞蛋handleTick功能,當我註銷event.delta財產,我得到「未定義」。我認爲如果我通過stage.update調用傳遞事件,那麼它會傳播到舞臺上的對象?

回答

1

Ticker的記號事件與DisplayObject(或Stage的)記號事件有點不同。 在這裏看到:在你的情況http://www.createjs.com/Docs/EaselJS/classes/DisplayObject.html#event_tick

因此,這或許應該工作:

e.handleTick = function(event) { 
    console.log(event.params[0].delta); 
    //params is all the parameter that you use in stage.update(p1, p2, ...); 
} 
+0

啊,我聽不懂的事件參數如何傳遞給一DisplayObject作爲「PARAMS」 - 謝謝! – koosa

+1

作爲任何人絆倒到這個答案的後續行動:EaselJS v0.8.0現在公開顯示列表滴答事件的'delta'以避免這種混淆。 – gskinner