🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@pbuk/game-loop

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pbuk/game-loop

Game loop for browser

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

game-loop

A game loop for browser.

Quick start

Include game-loop from CDN.

<script src="https://cdn.jsdelivr.net/npm/@pbuk/game-loop@1"></script>

Create the callbacks that define the game.

const config = {
  // Things that stay the same.
};

const getInitialState = (config) => {
  return {
    // Things that change.
  };
};

const update = ({ config, state, frameLength, runTime, gameState }) => {
  // Update state (don't change anything else).
};

const render = ({ config, state, frameLength, runTime, gameState }) => {
  // Update all displays (don't change anything).
};

Create and manage the game loop.

// Set up the game and call `update` and `render` once with gameState = 'notStarted'.
const { start, stop, reset } = GameLoop.createGame({ config, getInitialState, update, render });

// Starts the game running, or resumes after `stop()`.
start();
// Stops the game (can be resumed with `start()`).
stop();
// Stops the game and resets the state to the initial state.
reset();

FAQs

Package last updated on 21 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts