Current Size:
Chakra BreakPoints
base0px
sm480px
md768px
lg992px
xl1280px
2xl1536px
Current Height:Width
widthpx
heightpx

Subjects

JavaScript Game Development

Date Created: 2023/06/20

Last Update: 2023/07/01

#javascript #game-dev #pattern

JavaScript Game Development

Different Solutions for Game Loops

requestanimation frame react - codepen

Simple Example requestAnimationFrame

function animate() {
// stuff for animating goes here
requestAnimationFrame(animate);
}
animate();

requestAnimationFrame wrapped in a time-out is a clean way of controlling the frame rate for vanilla.js games.

let framesPerSecond = 10;
function animate() {
setTimeout(function() {
requestAnimationFrame(animate);
// animating/drawing code goes here
}, 1000 / framesPerSecond);
}

EXAMPLE

var promise = new Promise(function(resolve, reject){
resolve(5);
});
promise.then(function(data){
return data * 2;
}).then(function(data){
return data + 20;
}).then(function(data){
console.log(data);
});
// log 30

JavaScript Game Dev Bugs

Chris Courses

Space Invaders

Reference

Standout Game assets

Asset Packs

Single Characters

More Notes

All Notes
HomeProjects

Links

Home Articles Notes Projects About Style Guide Site Credits

Contact

 [email protected]

Location

🌎 Earth