Jump to content

[Arcade Physics] Colliding against a group of groups


codevinsky
 Share

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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