Posted by & filed under Tips.

The enterframe event is dispatched in the order shown below. Keep in mind that inside the Game object, enterframe is the last thing to happen. The very last thing. Even before an enterframe is dispatched, all objects’ ages are incremented. (Immediately after an element is added to a display tree, the age of the first enterframe is 1.)

  • Game.rootScene (rootScene.tl)
    • Group (Group.tl)
      • Sprite (Sprite.tl)
      • Sprite (Sprite.tl)
    • Group (Group.tl)
      • Sprite (Sprite.tl)
      • Sprite (Sprite.tl)
  • Game

EventTarget.js

dispatchEvent: function(e) {
    e.target = this;
    e.localX = e.x - this._offsetX;
    e.localY = e.y - this._offsetY;
    if (this['on' + e.type] != null){
        this['on' + e.type](e);
    }
    var listeners = this._listeners[e.type];
    if (listeners != null) {
        listeners = listeners.slice();
        for (var i = 0, len = listeners.length; i < len; i++) {
            listeners[i].call(this, e);
        }
    }
}

Core.js

_tick: function() {
    var now = this.getTime();
    var e = new enchant.Event('enterframe');
    e.elapsed = now - this.currentTime;
    this.currentTime = now;

    var nodes = this.currentScene.childNodes.slice();
    var push = Array.prototype.push;
    while (nodes.length) {
        var node = nodes.pop();
        node.age++;
        node.dispatchEvent(e);
        if (node.childNodes) {
            push.apply(nodes, node.childNodes);
        }
    }

    this.currentScene.age++;
    this.currentScene.dispatchEvent(e);
    this.dispatchEvent(e);

    this.dispatchEvent(new enchant.Event('exitframe'));
    this.frame++;
},

This post is also available in: Japanese

Comments are closed.