animation-frame-loop
Version:
A small wrapper to take care of tracking delta time between frames. Useful for animations or other frame reliant things.
37 lines (26 loc) • 1.31 kB
Markdown
# Animation Frame Loop
[](https://www.npmjs.com/package/animation-frame-loop)
[](https://www.npmjs.com/package/animation-frame-loop)
[](https://bundlephobia.com/package/animation-frame-loop)
A small package to keep track of frame related things, most notably deltaTime. Useful when creating animations that need to be consistent with varying frame counts.
### Installation
Install using Yarn or NPM, or any other package manager you might prefer.
```js
yarn add animation-frame-loop
```
```js
npm install animation-frame-loop
```
## Usage
```js
import { AnimationFrameLoop } from "animation-frame-loop"
const loop = new AnimationFrameLoop(({ deltaTime, totalElapsedTime, currentFps }) => {
// Do your thing
})
// Destroy the loop when you're done
loop.destroy()
```
`deltaTime` provides the time between the previous and the current frame.
`totalElapsedTime` provides the total time the loop has run for
`currentFps` provides the frames per second for the current second.
`.destroy()` can be called to destroy the loop, stopping the callback from being called.