Jump to content

Setting all sprites in a group to collide with one another


ForgeableSum
 Share

Recommended Posts

It's easy to set collide between two sprites you know the names of. But how does one set collide to all sprites in a group (with each other)? In other words, the parameters aren't sprite1 colliding with sprite 2 but every sprite in a group colliding with every sprite in the same group.  

 

I'm sure I could accomplish this with a nested foreach loop, but I'm looking for something less dirty. 

Link to comment
Share on other sites

  • 1 year later...

Hi,

I have a problem with collide in one group.

Create group:

 

    this.animal = this.game.add.physicsGroup();
         this.game.physics.arcade.enable(this.animal);  
     this.animal.enableBody = true;  

 

Adding animals to the group:

this.sheep =this.animal.create(zwierzex, zwierzey, 'sheepwalk');

Collision:
 

    this.game.physics.arcade.collide(this.player, this.blockedLayer);
    this.game.physics.arcade.collide(this.player, this.animal);
    this.game.physics.arcade.collide(this.animal);
    this.game.physics.arcade.collide(this.animal, this.blockedLayer, this.stopanimzwierz, null, this);

 

 

There are colliding wiht everything else but not with each other in the same group.. anuone know why?

Please help :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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