Jump to content

Collision Detection WITHIN a group using P2 Physics


NEWBIE21
 Share

Recommended Posts

Hi Everyone,

 

I'm a newbie to Phaser, so please forgive me if this question is really basic, but I'm actually wondering if it is possible to create a single group containing say, for example balls, and when these balls from the same group collide with eachother they change color. I set them up using the P2 PHYSICS System. If this is possible I would assume I'd use the "forEach" but I'm not sure exactly how. I'm familiar with setting up collision handlers between groups but not WITHIN Groups.

 

Is this possible with Phaser? And if so, how?

 

Thanks for the help :)

Link to comment
Share on other sites

I'm not sure I understand the postbroadphase callback example, because if it checks collision pairs, can you call a function on it? lets say two sprites in my group are colliding can i call a function on that colliding pair like make them change color? Because in the check veg function I said :

 if ((body1.sprite.name === 'ship' && body2.sprite.frame === 4) || (body2.sprite.name === 'ship' && body1.sprite.frame === 4))    {        return false;    }    body1.tint = Math.random() * 0xffffff;    body2.tint = Math.random() * 0xffffff;    return true;            }

what I tried to do was make whatever collided beside the ship and the green pepper change color. but that didn't work, so what am i doing wrong? or does postbroadphase callback only allow you to check for collision pairs but not actually call a function on them?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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