Jump to content

setBodyContactCallback box2d excutes callback twice?!HELP


rhllor
 Share

Recommended Posts

 

game.elements.ship.body.setBodyContactCallback(game.elements.rightMap, function (destroy){

 

  game.elements.ship.body.velocity.y -= -5;

  game.elements.ship.body.x = game.width*0.5;

  game.elements.ship.body.y = game.height*0.5;

  this.lostLife();

 

            }, this);

Link to comment
Share on other sites

  • 2 months later...

I have a similar situation where I am using setBodyContactCallback to trigger something when it hits a sensor, but I only want the callback to fire once. Since there is no removeBodyContactCallback, I found that if I set the callback again with the function parameter empty it effectively kills it. Seems like there should be a better way to do this, but I'm not finding it in the Phaser Box2D Plugin API docs.
 

ball.setBodyContactCallback(levelScene.getBody('sensor1'), function () {	ball.setBodyContactCallback(levelScene.getBody('sensor1'));//kills callback	console.log("ball hit sensor!");			}});
Link to comment
Share on other sites

  • 3 weeks later...
 Share

  • Recently Browsing   0 members

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