accurate-game-loop
v2.0.0
Published
A very accurate game loop, down to the nanosecond
Downloads
5
Maintainers
Readme
Accurate Game Loop
A library for nodejs game loops (not meant for browser), this package is pretty much the most accurate you can get with nodejs
Install
npm install accurate-game-loop
Usage / Documentation
const Loop = require('accurate-game-loop');
Creating a loop
const timesPerSecond = 60;
const update = () => {
// do something smart
};
const loop = new Loop(update, timesPerSecond);
Starting a loop
loop.start();
// or
const loop = new Loop(...params).start();
Stopping a loop
loop.stop();
Options:
new Loop(
update,
timesPerSecond,
{...options}
)
Logs
This automatically enables every type of log internally (Useful for debug)
Implementation:
new Loop(
update,
timesPerSecond,
{ logs: true }
)
Example:
Delta Log
This automatically logs the time differences between the update calls
Implementation:
new Loop(
update,
timesPerSecond,
{ delta_log: true }
)
Example:
Difference Log
This automatically logs the time shifts that the code makes internally
Implementation:
new Loop(
update,
timesPerSecond,
{ dif_log: true }
)
Example:
Time Function
This allows you to specify the time function you want (expects it to return in nanoseconds)
Example / Implementation:
new Loop(
update,
timesPerSecond,
{ time_fn: () => Date.now() * 1e6 }
)