rhllor Posted July 30, 2015 Share Posted July 30, 2015 hello does anyone know why setBodyContactCallback executes the callback function twice ? and is there a way to make it execute only once. thanks Link to comment Share on other sites More sharing options...
rhllor Posted July 30, 2015 Author Share Posted July 30, 2015 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 More sharing options...
kleepklep Posted October 20, 2015 Share Posted October 20, 2015 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 More sharing options...
kleepklep Posted November 6, 2015 Share Posted November 6, 2015 Digging around in Body.js for something else I came across this: * @param {function} callback - The callback to fire on contact. Set to null to clear a previously set callback.So passing no function like I did is intended behavior. Lucky guess! Skeptron 1 Link to comment Share on other sites More sharing options...
Recommended Posts