Time for action – setting up the world step loop
We will make the world time advance by carrying out the following steps:
- In order to advance the world step, we have to call the
step
function in the world instance periodically. We usedsetTimeout
to keep calling thestep
function. Put the following function in our JavaScript logic file:function updateWorld() { // Move the physics world 1 step forward. carGame.world.Step(1/60, 10, 10); // display the build-in debug drawing. if (shouldDrawDebug) { carGame.world.DrawDebugData(); } }
- Next, we will set up an interval in the
initGame
method:setInterval(updateWorld, 1/60);
- We will again simulate the world in a browser. The box is created at the initialized position and falls on the ground correctly. The ...
Get HTML5 Game Development by Example : Beginner's Guide - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.