2.0.0 • Published 3 years ago

accurate-game-loop v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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:

Screenshot

Delta Log

This automatically logs the time differences between the update calls

Implementation:

new Loop(
    update,
    timesPerSecond,
    { delta_log: true }
)

Example:

Screenshot

Difference Log

This automatically logs the time shifts that the code makes internally

Implementation:

new Loop(
    update,
    timesPerSecond,
    { dif_log: true }
)

Example:

Screenshot

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 }
)

If you have any questions, you can make a github issue or dm me on discord at ZeroTix#6300 (I respond quick)

2.0.0

3 years ago

1.1.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago