motor-loop
TypeScript icon, indicating that this package has built-in type declarations

1.0.24 • Public • Published

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

  • start: "bun run index.ts",
  • bundle: "bun run bundler/bundler.ts",
  • list: "bun run samples/list-scripts.tsx",
  • example: "cd example && bun start && cd ..",
  • fileSample: "bun run samples/file.tsx && cat samples/data/test.json",
  • httpSample: "bun run samples/server.tsx"

Run example

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

Github Source

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

/motor-loop/

    Package Sidebar

    Install

    npm i motor-loop

    Weekly Downloads

    5

    Version

    1.0.24

    License

    MIT

    Unpacked Size

    31.2 kB

    Total Files

    15

    Last publish

    Collaborators

    • vincentlequang