ZoomBox Posted June 18, 2014 Share Posted June 18, 2014 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 More sharing options...
lewster32 Posted June 18, 2014 Share Posted June 18, 2014 I believe the problem has been fixed in dev, but essentially sprite.alive is not set within the Sprite object itself. You should be able to fix this just by adding this.alive = true to your constructor (after Phaser.Sprite.call). Link to comment Share on other sites More sharing options...
j0hnskot Posted June 18, 2014 Share Posted June 18, 2014 the strange thing is that even if the this.alive is not set, it sets it when .kill() is called. If what Lewis told you worked let us know. Link to comment Share on other sites More sharing options...
ZoomBox Posted June 18, 2014 Author Share Posted June 18, 2014 Oh man thank you, I found this answer by myself a second ago and you're confirming it. I'll try. Edit: Perfect ! It works ! Link to comment Share on other sites More sharing options...
lewster32 Posted June 18, 2014 Share Posted June 18, 2014 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 More sharing options...
ZoomBox Posted June 18, 2014 Author Share Posted June 18, 2014 Yeah that's how Group.iterate works I think:http://docs.phaser.io/Phaser.Group.html#iterate Link to comment Share on other sites More sharing options...
Recommended Posts