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 プロパティをログアウトすると、「undefined」になります。イベントを stage.update 呼び出しで渡すと、ステージ上のオブジェクトに伝播すると思いましたか?

4

1 に答える 1

1

のtick-event は、の(またはの) tick- Tickerevent とは少し異なります。ここを参照してください: 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 に答える