dzucconi / frame-interval

Execute a function n-times per second, on requestAnimationFrame

Home Page:https://www.npmjs.com/package/frame-interval

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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();

About

Execute a function n-times per second, on requestAnimationFrame

https://www.npmjs.com/package/frame-interval

License:MIT License


Languages

Language:TypeScript 100.0%