ihorbra Posted November 3, 2015 Share Posted November 3, 2015 Hey. I want create a specific zone (sprite named zone) and detect object (named gift) entrance on it on P2 Physics but I can't. I have tried to use `setPostBroadphaseCallback` to disable sprites (zone sprite and player sprite) collision. Then I try to use `createBodyCallback` but it doesn't work. The player and zone are sprites. How can I do this? Code: http://paste.ofcode.org/ZAbvUtvvyQX6WhWz2yLA6j Maybe `zone` should be not the sprite? Can you recommend me best practice for this issue? Link to comment Share on other sites More sharing options...
jmp909 Posted November 5, 2015 Share Posted November 5, 2015 why not just add whatever functionality you need in the isZone function itself? that's what he's done here<= game.physics.p2.setPostBroadphaseCallback(checkOverlap, this); //this is used to start the check // if this returns true a collision could happen.. if false it will not collidefunction checkOverlap(body1, body2) { if ((body1.sprite.name === 'ship' && body2.sprite.name === 'bullet') || (body2.sprite.name === 'ship' && body1.sprite.name === 'bullet')){ dosomething(); //whatever you need on overlap return false; } return true;} maybe there are other methods.. i'm still looking also I'm assuming you didn't mean to leave the arcade physics code in there Link to comment Share on other sites More sharing options...
jmp909 Posted November 5, 2015 Share Posted November 5, 2015 actually you can also set the zone body's shape as a sensorhttp://phaser.io/sandbox/SYDSCqTK/play// set the green pepper to overlap, rather than collideif(veg.frame==4) { veg.body.data.shapes[0].sensor=true} // we can check overlap "collision" with the green pepper sensor as well as normal collision with the other veggies nowship.body.onBeginContact.add(shipCollision, this) Link to comment Share on other sites More sharing options...
ihorbra Posted November 6, 2015 Author Share Posted November 6, 2015 Thank you! But now I have another issue with overlapping: http://www.html5gamedevs.com/topic/18449-setpostbroadphasecallback-doesnt-work-correct/ Link to comment Share on other sites More sharing options...
Recommended Posts