phaserjs / phaser-ce-examples

Contains hundreds of source code examples and related media for the Phaser HTML5 Game Framework.

Home Page:http://phaser.io/examples

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Groups/replace.js example is broken

shinho opened this issue · comments

This is broken because Sprite#group returns undefined. This could be fixed by adding the property to the Sprite class, but since I'm new to Phaser don't know why was it changed.
/**

  • @name Phaser.Sprite#group
  • @Property {string} group - If Sprite is in a group return the group name
    */
    Object.defineProperty(Phaser.Sprite.prototype, "group", {
    get: function () {
    if (parent && parent.type == Phaser.GROUP)
    {
    return this.parent.name;
    }
    else
    {
    return null;
    }
    }
    });

You also need to add the names to the groups after creating them:
left.name = "left";
right.name = "right";

or at game.add.group() time

Good catch. This is now fixed.