Jump to content

group.getFirstDead returning null (Working on the gemmatch example)


ZoomBox
 Share

Recommended Posts

Hello !

My problem is quite simple I guess:

 

I'm working on the gemmatch example (URL).

In the example, there is a Phaser.Group named gems and we create a gem by using gems.create(x, y, "texture");

In my version, I wanted a gem to be a custom Sprite named "Piece" so I extended it this way:

Piece = function (game, _x, _y, _texture, _type) {    Phaser.Sprite.call(this, game, _x, _y, _texture);    this.type = _type;    game.add.existing(this);    gems.add(this);};Piece.prototype = Object.create(Phaser.Sprite.prototype);Piece.prototype.constructor = Piece;

Actually, I currently just added "type" to my Piece class.

Notice that I add the Piece to the gems group during its creation.

 

By doing this way, everything is fine (it's added to the gems group) BUT when I kill one gem and then I try to call gems.getFirstDead() it returns null...

Don't understand what's different between the original code and mine.

Link to comment
Share on other sites

I think (but don't quote me on this) that the fault lies with Group.iterate (which is used by the Group.forEach methods) which may fail if any objects in the iterated collection are missing the provided key altogether. I can't be sure, and I can't currently test this but that's my theory.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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