Simulation Strategy

There are several applications, such as the shooting game example, that require all intermediate frames to ensure the integrity of the outcome. These applications include working with collision detection, physics simulations, or artificial intelligence for games. For games, we need to update the object's positions at a constant rate. We do so by directly calculating the next position for the objects inside the timer callback:

const animationRate = 30; // 30 ms
const deltaPosition = 0.1;

function animate(deltaP) {
// Calculate object positions based on deltaP
}

function onFrame() {
animate(deltaPosition);
}

function startAnimation() {
setInterval(onFrame, animationRate / 1000);
}

This may lead to frozen frames that occur when there is a long list of blocking events because the object's positions would not be updated in a timely manner.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.197.201