Jump to content

Group.getChildIndex not working after upgrade to 2.4.2


Recommended Posts

I've been working on a prototype for the last few weeks using Phaser v2.2.2 with moderate success. Earlier this week I decided it was probably time to update Phaser to keep current. Everything went relatively smoothly except for this one issue I've been dealing with since.


Before posting here, I did as much research as I could to see if any breaking changes had come with this new version regarding groups and sprites. I didn't see anything in the release notes, nor did I see any changes in the code when I looked. So I'm hoping someone with more insight could help me out here.

In a loop, I'm adding invisible sprites to a group, with coordinates surrounding another sprite:

var sprite = this._tile_collisions.create(position.x, position.y);sprite.valid = true;sprite.height = 50;sprite.width = 50;sprite.inputEnabled = true;sprite.events.onInputDown.add(this._canMoveToTile, this);this._game.physics.arcade.enable(sprite);this._tile_collisions.add(sprite);
And then in an update method I'm checking for overlap with another group:

this._game.physics.arcade.overlap(    collisions,    this._tile_collisions,    function (collider, tile) {        // I cannot get the index of this child        var index = this._tile_collisions.getChildIndex(tile);    },    null,    this);
I should probably mention that the onInputDown event on the sprite removes the children from the group (using removeChildren()), tweens the player sprite to a new position, and then adds new sprites to the group. When create() is called for the first time, things run fine. However, after that sprite movement everything falls apart.

Error: The supplied DisplayObject must be a child of the caller
This used to work beautifully until I upgraded. So my question is: has something changed that I'm not aware of that should alter the way I'm writing this? If so, how can I get this overlap to work?

Any help is greatly appreciated, and if I need to give more details just let me know.

Link to comment
Share on other sites

I ended up finding a solution almost immediately after posting (go figure) that seems to work for my situation. I'm now using the process callback to return a custom flag I've put on my sprites to store their validity. It's not pretty and doesn't really solve the underlying problem, but I'm able to move on now.

this._game.physics.arcade.overlap(    collisions,    this._tile_collisions,    function (collider, tile) {        var index = this._tile_collisions.](tile);    },    function (collider, tile) {        return tile.valid;    },    this);
So if anyone has any insight please let me know.
Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...