Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattdesl/raf-loop
a minimal requestAnimationFrame render loop
https://github.com/mattdesl/raf-loop
Last synced: about 2 months ago
JSON representation
a minimal requestAnimationFrame render loop
- Host: GitHub
- URL: https://github.com/mattdesl/raf-loop
- Owner: mattdesl
- License: mit
- Created: 2014-12-05T03:14:16.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-09-16T09:01:51.000Z (about 6 years ago)
- Last Synced: 2024-10-17T16:49:57.590Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 54
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# raf-loop
[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)
A minimal requestAnimationFrame render loop for node and the browser, using high-performance timing where possible.
```js
const loop = require('raf-loop')const engine = loop((dt) => {
// delta time in milliseconds
}).start()
```## Usage
[![NPM](https://nodei.co/npm/raf-loop.png)](https://nodei.co/npm/raf-loop/)
#### `engine = loop([fn])`
Creates a new loop with an optional function to receive tick events. The function will be called with delta time as the first parameter, in milliseconds.
#### `engine.start()`
Starts the render loop and returns this engine, for chaining.
#### `engine.stop()`
Stops the render loop and cancels the currently requested animation frame.
#### `engine.on('tick', fn)`
Attaches another function to the render loop.
## License
MIT, see [LICENSE.md](http://github.com/mattdesl/raf-loop/blob/master/LICENSE.md) for details.