Skip to content

wmcmurray/game-loop-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

game-loop-js 🎮 🔁

Features :

  • Lightweight
  • Built with speed in mind
  • Ensure consistent and stable frame-rates (based on the targeted FPS of your choosing)
  • The targeted FPS is tweakable on-the-fly (while the game is running)
  • This implementation does not have a requestAnimationFrame loop, it let you implement it yourself or not (because in some cases it's handled by the framework, ex: threejs in a WebXR project)

Usage

Three.js

import gameLoopJs from 'game-loop-js'

const gameLoop = gameLoopJs(function(deltaTime) {
  // render code...
});

renderer.setAnimationLoop( gameLoop.loop );

requestAnimationFrame()

import gameLoopJs from 'game-loop-js'

const gameLoop = gameLoopJs(function(deltaTime) {
  // render code...
});

function animate( time ) {
  gameLoop.loop( time );
  requestAnimationFrame( animate );
}
requestAnimationFrame( animate );

Browser

<script type="text/javascript" src="/dist/bundle.umd.js"></script>

<script type="text/javascript">
  const gameLoop = createGameLoop(function(deltaTime) {
    // render code...
  });

  function animate( time ) {
    gameLoop.loop( time );
    requestAnimationFrame( animate );
  }
  requestAnimationFrame( animate );
</script>

About

Reliable and versatile game loop implementation

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published