1 decade ago by yikidu
I am trying to destroy a box2d body on collision and it's not working. I am able to detect the collision and destroy the impact entity by passing it's name in the userData of the body, but the box2d entity is still there invisibly. Here is the code.
init: function () { this.score = 0; this.loadLevel(LevelTest); var myListener = new b2.ContactListener(); myListener.BeginContact = function (contact) { var body1 = contact.GetFixtureA().GetBody(); var body2 = contact.GetFixtureB().GetBody(); var player = ig.game.getEntitiesByType(EntityPlayer)[0]; if (body2.userData != 'cactus' && body2.userData != 'player' && body1.userData == 'player') { var other = ig.game.getEntityByName(body2.userData); ig.world.DestroyBody(body2); other.kill(); } else if (body2.userData == 'cactus') { player.kill(); ig.system.setGame(MyGame); } var playerSpeed = parseInt(player.body.GetLinearVelocity().y) + 20 + parseInt(ig.game.score); ig.game.score = playerSpeed.toFixed(0); }; ig.world.SetContactListener(myListener); }