Naturally Pacifist Marsupials

    frame-delta
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.2 • Public • Published

    frame-delta

    Utility for counting frame time and frames per interval.

    Usage

    Install

    npm install frame-delta --save
    

    Code

    var FrameDelta = require("FrameDelta").FrameDelta;
    var sleep = require("sleep-promise");
     
    // Create a new `FrameDelta` instance and tell it that we are aiming for
    // 30 FPS. The `1000` (given to the constructor in the line below) is the
    // interval (in milliseconds) that we want the `FrameDelta` to update its
    // FPI.
    var frames = new FrameDelta(1000);
    frames.targetFPI = 30;
     
    // Enter a render/update loop.
    while (windowIsOpen) {
        render();
        update();
     
        // We can get the frames per interval (FPI) and frame time from the
        // instance. These values will be `0` the first time we print them, as
        // it takes at least one render/update loop iteration before these values
        // can be determined.
        console.log("FPS: " + frames.fpi);
        console.log("Frame Time: " + frames.frameTime);
     
        // Based on the current frame time (duration between last two frame
        // updates), the `FrameDelta` instance will suggest the optimal amount
        // of time we can suspend the thread so we don't hammer the CPU, whilst
        // still allowing us to get our target FPI.
        await sleep(frames.loopSleepTime);
     
        // Tell the instance that the frame is over.
        this.frames.nextFrame();
    }

    Build

    frame-delta is built using gulp. You can invoke the build process by using either gulp directly, or via an npm script which calls gulp. (Basically, both the npm script and the gulp command do exactly the same thing.)

        npm run build
        // Or
        gulp build

    License

    See the LICENSE file for license information.

    Install

    npm i frame-delta

    DownloadsWeekly Downloads

    2

    Version

    1.1.2

    License

    MIT

    Unpacked Size

    12.9 kB

    Total Files

    11

    Last publish

    Collaborators

    • mgthomas99