Jump to content

[Arcade Physics] Colliding against a group of groups


Recommended Posts

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


  • Recently Browsing   0 members

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