Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Is object in zone


ihorbra
 Share

Recommended Posts

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

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

actually you can also set the zone body's shape as a sensor

http://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

 Share

  • Recently Browsing   0 members

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