Skip to content

Painfully basic script just to shortcut setting up requestAnimationFrame loops in experiments.

License

Notifications You must be signed in to change notification settings

tdous/anim-loop-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

anim-loop-engine

Painfully basic lib just to shortcut setting up requestAnimationFrame loops in experiments.

Installing

npm install --save tdous/anim-loop-engine

Usage

import { AnimLoopEngine } from 'anim-loop-engine';

const engine = new AnimLoopEngine();

const someTaskToRunEachFrame = () => { ... };
const someTaskToRunSecond = (ts) => {
  // Maybe so domething with the timestamp passed to each frame task
  ...
};
const yetAnotherFrameTask = () => { ... };

// Add single tasks... (optionally keep the returned task ID for later)
engine.addTask(someTaskToRunEachFrame);

// ...or multiple - they are called in added order - tasks IDs returned as array
const someTaskIds = engine.addTasks([someTaskToRunEachFrame, someTaskToRunSecond]);

// Start the loop
engine.start()

// Add another task while running
const anotherTaskId = engine.addTask(yetAnotherFrameTask);

// Delete a task - deleting 'someTaskToRunSecond' via the returned tasks ID
engine.deleteTask(someTaskIds[1]);
// ...so the engine is now calling 'someTaskToRunEachFrame' then 'yetAnotherFrameTask'

// Stop whenever you want
engine.stop();

About

Painfully basic script just to shortcut setting up requestAnimationFrame loops in experiments.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published