@obsidianjs/main-loop

0.1.3 • Public • Published

main-loop

The main-loop module can be used to render 2d or 3d, or to do anything at a rather fixed time interval. It's using RequestAnimationFrame, so to get a constant time interval, 60 must be a multiple of your desired fps. Also, the fps cannot exceed the screen refresh rate for now.

You can add the idleFps, activeFps and debug config parameters to change this module behavior:

app.use(mainLoop,{
    config : {
        // The target fps when the loop is running normally (-1 by default => fps = screen refresh rate)
        activeFps: 30,

        // The target fps when the window is not focused (0 by default)
        idleFps: 5,

        // show loop information in the console (false by default)
        debug: true,
    }
});

Add some callbacks function to be executed inside the loop, like your render methods:

mainLoop.addCallback((loopInfo) => {
    renderMyScene();
    console.log(JSON.stringify(loopInfo));
})

Or just listen to the update event:

self.app.events.on("@main-loop.update",(loopInfo) => {
    renderMyScene();
    console.log(JSON.stringify(loopInfo));
});

Start and stop the loop when you need it:

mainLoop.start();
// ........
mainLoop.stop();

Documentation

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.3
    33
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.3
    33
  • 0.1.2
    0
  • 0.1.1
    0

Package Sidebar

Install

npm i @obsidianjs/main-loop

Weekly Downloads

33

Version

0.1.3

License

BSD-3-Clause

Unpacked Size

19.8 kB

Total Files

8

Last publish

Collaborators

  • breush
  • eole211
  • flozz
  • leonicolle
  • risq
  • tneullas
  • wanadmin