0

我刚开始使用 EaselJS,我遇到了我的第一个障碍。我扩展了 Container 对象以创建一个名为 Egg 的新类:

(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);
}

在 Egg 的 handleTick 函数中,当我注销 event.delta 属性时,我得到“未定义”。我想如果我通过 stage.update 调用传入事件,那么它会传播到舞台上的对象吗?

4

1 回答 1

1

's 滴答事件与's(或's)滴答事件Ticker略有不同。见这里:http ://www.createjs.com/Docs/EaselJS/classes/DisplayObject.html#event_tickDisplayObjectStage

所以在你的情况下,这应该可以工作:

e.handleTick = function(event) {
    console.log(event.params[0].delta);
    //params is all the parameter that you use in stage.update(p1, p2, ...);
}
于 2013-08-28T18:08:10.953 回答