NEWBIE21 Posted December 8, 2015 Share Posted December 8, 2015 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 More sharing options...
ekeimaja Posted December 8, 2015 Share Posted December 8, 2015 Have you looked these tutorials? http://phaser.io/examples/v2/category/p2-physics Link to comment Share on other sites More sharing options...
NEWBIE21 Posted December 9, 2015 Author Share Posted December 9, 2015 Heya yes, the problem is I want to detect collisions within a SINGLE group, not between groups Link to comment Share on other sites More sharing options...
ekeimaja Posted December 9, 2015 Share Posted December 9, 2015 How about this? http://phaser.io/examples/v2/p2-physics/postbroadphase-callback Link to comment Share on other sites More sharing options...
NEWBIE21 Posted December 10, 2015 Author Share Posted December 10, 2015 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 More sharing options...
NEWBIE21 Posted December 11, 2015 Author Share Posted December 11, 2015 solution provided by Skeptron! Thank you, body1.sprite.tint = Math.random() * 0xffffff;body2.sprite.tint = Math.random() * 0xffffff; Link to comment Share on other sites More sharing options...
Recommended Posts