npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@spithacode/game-loop

v1.0.2

Published

Simple fixed timestamp based game loop.

Downloads

7

Readme

@spithacode/game-loop

A TypeScript game loop implementation with fixed timestep pattern, perfect for creating smooth and consistent game animations. This package provides a singleton game loop that maintains consistent update rates while allowing for variable rendering framerates.

Features

  • Fixed timestep updates for consistent game logic
  • Variable rendering framerate
  • FPS control (20-144 FPS)
  • Singleton pattern for global state management
  • Written in TypeScript with full type support
  • Zero dependencies

Installation

Using pnpm (recommended):

pnpm add @spithacode/game-loop

Using npm:

npm install @spithacode/game-loop

Using yarn:

yarn add @spithacode/game-loop

Usage

import { getGameLoop } from "@spithacode/game-loop";

// Get the game loop instance
const gameLoop = getGameLoop();

// Game state
let playerX = 0;
let playerY = 0;
const PLAYER_SPEED = 100; // pixels per second

// Update function - runs at fixed timestep
const update = (dt: number) => {
  // dt is in seconds
  playerX += PLAYER_SPEED * dt;
  playerY += PLAYER_SPEED * dt;
};

// Render function - runs as fast as possible
const render = () => {
  // Update your canvas or DOM here
  console.log(`Player position: (${playerX}, ${playerY})`);
};

// Start the game loop
gameLoop.start(update, render);

// Optionally set target FPS (default is 60)
gameLoop.setTargetFPS(144); // Values between 20-144 are supported

// Stop the loop when needed
// gameLoop.stop();

API Reference

getGameLoop()

Returns the singleton instance of the GameLoop class.

GameLoop Class

Properties

  • time: number - Get the total elapsed time since the game loop started

Methods

  • start(update: (dt: number) => void, render: () => void): void

    • Starts the game loop
    • update: Function called at fixed intervals with delta time in seconds
    • render: Function called as often as possible for rendering
  • stop(): void

    • Stops the game loop
  • setTargetFPS(fps: number): void

    • Sets the target FPS for updates (between 20 and 144)

Technical Details

The game loop uses a fixed timestep pattern which:

  • Ensures consistent physics and game logic updates
  • Prevents spiral of death in slow frames
  • Separates update logic from rendering
  • Maintains smooth animations even under varying system performance

Default values:

  • Default FPS: 60
  • Minimum FPS: 20
  • Maximum FPS: 144

License

MIT © [Sid Ali Assoul]

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any issues or have questions, please file an issue on the GitHub repository.