Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

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);
        }

1 decade ago by yikidu

If anyone has been able to kill both an impact entity and it's box2d body I'd really love to know how you did it. Any help at all would be appreciated.

1 decade ago by alexandre

ig.Box2DEntity takes care of that for you. It injects a call to ig.world.DestroyBody( this.body ) before invoking this.parent.

1 decade ago by unstoppableCarl

I am also having this problem

1 decade ago by mimik

One of the problems that can accure is that the the kill function dosen't get called in the same tick. so the animation is killed but not the box2d body.

To work around this you can in your update function make an boleean calling this.kill.



killstuff:function{
// kill the player

this.gotkilled = true;

}



update:function(){

if(this.gotkilled){
  this.kill();
}  

Page 1 of 1
« first « previous next › last »