codevinsky Posted April 7, 2014 Share Posted April 7, 2014 I have a group that has groups inside of it. This might be bad design and I'm willing to take a look at a different way of doing it.var MyGroup = function(game, parent) { Phaser.Group.call(this, game, parent); this.add(spriteWithPhysicsBody); this.add(anotherSpriteWithPhysicsBody);}; MyGroup.prototype = Object.create(Phaser.Sprite);MyGroup.prototype.constructor = MyGroup; in my play state:create: function() { this.player = game.add.sprite(0,0, 'player'); this.groups = game.add.group(); this.groups.add(new MyGroup(this.game, this.group);},update: function() { this.game.physics.arcade.collide(this.player, this.groups, this.collisionHandler, null, this);}This doesn't work. Nothing ever collides. But if I do this: this.groups.forEachExists(function(group) { this.game.collide(this.player, group, this.collisionHandler, null, this);}, this);Everything works. Am I making it too complicated, or is this the only way to do it? Link to comment Share on other sites More sharing options...
rich Posted April 8, 2014 Share Posted April 8, 2014 collide doesn't iterate into child groups, it just looks for display objects at the top level. Although I guess it probably ought to, I'll add it to the list to investigate further. Link to comment Share on other sites More sharing options...
Recommended Posts