Stepping into the world
Once the world has been created, the simulation must actually be run. You can do this by calling the Step
function of the b2World
class, usually in the update
function of your game, as follows:
world_->Step(dt, 8, 3);
The three parameters passed to the Step
function are the time-step, the number of velocity iterations, and the number of position iterations, respectively. The variable dt
passed into the Step
function is passed to us from the update
function of our GameWorld
class, and the value held by dt
is that of a variable time-step. We use the term variable to describe this value because the amount of time the Cocos2d-x engine will take to finish one single tick might vary continuously.
One drawback of using a variable time-step is that it makes the entire simulation hardware dependent. Thus the simulation might run faster on a machine having a powerful configuration, while it might run significantly slower on a machine having a poor configuration. Considering...