motor-loop

npm version

Motor loop is a typescript library that runs a game loop continuously.

Notably, it adapts to frameRate to ensure your game always runs smoothly when the monitor refresh rate goes above or below 60hz.

It’s also used to schedule updates.

Usage

  const motor = new Motor();

  //  This will cause your refresh method to be called continously at the frameRate specified
  motor.loop({
    refresh: (updatePayload) {
      //  execute continously
      doSomethingWith(updatePayload.data);
    }
  }, data, frameRate);
  
  //  You can also schedule an update. The update will only be executed one time
  motor.scheduleUpdate({
    refresh: (updatePayload) {
      //  update something
    }
  });

Install bun

https://bun.sh/

curl -fsSL https://bun.sh/install | bash

Commands

Run example

https://jacklehamster.github.io/motor-loop/example/

Github Source

https://github.com/jacklehamster/motor-loop/