🔄
requestAnimationFrame Wrapper
Cleanly manage and orchestrate your render loops without repetitive boilerplate.
A lightweight animation and render loop manager with built-in high precision clock and FPS capping.
Built with LoopR.js
A render loop managed by Player, updating state with delta time and capped at 30 FPS.
import { Player } from '@1pizzateam/loopr';
import { Vec2 } from '@1pizzateam/spock';
const position = new Vec2(0, 100);
const speed = 100; // move 100 pixels per second
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
const animation = new Player((delta) => {
// Clear the canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Update state using delta time
position.x += speed * delta;
if (position.x > canvas.width) position.x = 0;
// Render
ctx.fillStyle = '#5b8cff';
ctx.fillRect(position.x, position.y, 50, 50);
});
// Optional: cap at 30 FPS
animation.capFPS(30);
// Start the loop!
animation.start();