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

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...