Skip to content

Instantly share code, notes, and snippets.

View lokshunhung's full-sized avatar
🐱

LS Hung lokshunhung

🐱
  • Hong Kong
View GitHub Profile
@lokshunhung
lokshunhung / RequestAnimationFrame_Renderer.ts
Created May 19, 2025 05:08
fps limited requestAnimationFrame
class Renderer {
#targetDelay: number;
#onTick: (elapsed: number) => void;
#lastTickTimestamp: number = 0;
#animationId?: number;
constructor(fps: number, onTick: (elapsed: number) => void) {
this.#targetDelay = 1_000 / fps;
this.#onTick = onTick;