accurate-game-loop

    2.0.0 • Public • Published

    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)

    Install

    npm i accurate-game-loop

    DownloadsWeekly Downloads

    25

    Version

    2.0.0

    License

    ISC

    Unpacked Size

    17.1 kB

    Total Files

    7

    Last publish

    Collaborators

    • zerotix