1 decade ago by lazer
Box2D implementation has been driving me crazy all weekend. My main problem right now is resizing entities. I understand that you can't resize with Box2D, so to change the size of an entity you have to destroy the shape and then recreate it with the new dimensions (if I'm understanding correctly). So I'm implementing crouch and attempting to do this like so in the player entity's update function:
I'm not even sure if this is a good way of doing it, but right now the creating of the resized shape appears to work. However I have no idea what to use when calling the DestroyShape function. How do I refer to the current shape to destroy it before creating the new resized shape? And then I'll need to destroy the new resized shape and recreate the full sized shape on uncrouch, but I'd be happy to just get the crouched shape right for now. I must be missing something stupidly blatant here.
// Crouch if (ig.input.state('crouch') && this.standing) { if (!this.crouching && !this.crouched){ console.log('destroy shape here'); this.body.DestroyShape(I DONT KNOW WTF TO PUT HERE); this.crouching = true; this.crouched = false; } if (this.crouching){ this.size.y = this.crouch; console.log('set shape here'); this.setShapeDef(); this.crouching = false; this.crouched = true; } this.currentAnim = this.anims.defaultCrouchIdle; }
I'm not even sure if this is a good way of doing it, but right now the creating of the resized shape appears to work. However I have no idea what to use when calling the DestroyShape function. How do I refer to the current shape to destroy it before creating the new resized shape? And then I'll need to destroy the new resized shape and recreate the full sized shape on uncrouch, but I'd be happy to just get the crouched shape right for now. I must be missing something stupidly blatant here.