frame-interval
TypeScript icon, indicating that this package has built-in type declarations

1.0.47 • Public • Published

frame-interval

What is this?

A library that allows you to limit the execution of requestAnimationFrame to n-frames per second for some value of n.

Why should I use this?

  • You want a requestAnimationFrame interface which runs at a lower speed or is bounded at some upper limit.

Installation

yarn add frame-interval

Usage

import { FrameInterval } from "frame-interval";

const FPS = 24;

// constructor FrameInterval(fps: number, callback: FrameIntervalCallback): FrameInterval

// type FrameIntervalCallback = (
//   props?:
//     | {
//         time: number;
//         frame: number;
//       }
//     | undefined
// ) => void;

const fi = new FrameInterval(FPS, ({ frame }) => {
  document.body.innerHTML = `${Math.floor(frame / FPS)} ${frame}`;
});

fi.start();
// ...
fi.stop();

Package Sidebar

Install

npm i frame-interval

Weekly Downloads

2

Version

1.0.47

License

MIT

Unpacked Size

12.2 kB

Total Files

18

Last publish

Collaborators

  • dzuc