Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A unity style event loop for Javascript that has callbacks for earlyUpdate, update, and lateUpdate. Select a target FPS or choose to update with monitor refresh rate.

License

NotificationsYou must be signed in to change notification settings

joezappie/update-loop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A unity style event loop for Javascript that has callbacks for earlyUpdate, update, and lateUpdate. Select a target FPS or choose to update with monitor refresh rate.

Instructions

To use this library, create a new update loop. The loop will start immediately.

const loop = new UpdateLoop(60, [mode]);

You can then register objects to the event loop, defining earlyUpdate, update and/or lateUpdate.

class MyObject {  earlyUpdate() {    // Code to perform first  }    update() {    // Normal execution level. Put things that order doesnt matter here  }    lateUpdate() {    // Code to perform last  }}const obj = new MyObject();loop.register(obj);

You can also stop an object from running on the event loop:

loop.unregister(obj);

Modes

There are two modes for the event loop:

  1. UpdateLoop.INTERVAL: Uses setInterval() (default)
  2. UpdateLoop.RAF: Uses requestAnimationFrame()

If you want to switch to using RAF:

const loop = new UpdateLoop(60, UpdateLoop.RAF);

In both modes you can specify a desired FPS. Depending on what your application is, one or the other might be better. If your doing animation with canvas or a 3d library, you might want to use RAF. The drawback is it works best with FPS like 15, 30, 60, 120. Getting an interval like 24 FPS would be less percise than using the INTERVAL mode.

In RAF Mode, if you would like the FPS to be uncapped, provide null for targetFPS. If an FPS is specified it will throttle the FPS.

API

Functions

// Stop the update looploop.stop();// Start the update looploop.start();

Properties

loop.jitter           // Difference between deltaTime and desired intervalloop.averageJitter    // Average jitter since the loop startedloop.frame            // How many frames have been generated since the loop started

About

A unity style event loop for Javascript that has callbacks for earlyUpdate, update, and lateUpdate. Select a target FPS or choose to update with monitor refresh rate.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp