Now we want to make the main character interact with our world.
We'll add some new methods to the Character
module as follows:
First we create an object to store our body and shapes as follows:
function Character:initializePhysics () self.physics = {}
Then we add a dynamic body to the physics simulation. This will be the body of our character as follows:
self.physics.body = PhysicsManager.world:addBody ( MOAIBox2DBody.DYNAMIC )
Now we position the body using the same initial position that we used for our rendered character as follows:
self.physics.body:setTransform ( unpack(character_object.position) )
Now we add a shape. We'll use a square that's the same size as the sprite (64 x 64 ). This is obviously far from ideal, because collisions may seem strange in some cases (it will feel like there was a transparent box around him), but in order to keep it simple, we can live with that.
self.physics.fixture = self.physics.body:addRect( -32, -32, 32,...