Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

loopsie

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loopsie

A gameloop that helps you handle state as well

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Loopsie

Loopsie allows you to quickly build and prototype simple games, by providing both a game loop and a simple state management system.

It does not have any opinion in regards to the visual output. Instead, clients can subscribe to state changes and handle them however they see fit.

Loopsie can be used in both node and the browser. It also is fully TypeScript typed.

Getting started

Installation

To install Loopsie, simply add it using your package manager of choice:

npm install loopsie

or

yarn add loopsie

Your first game loop

import { GameLoop, perSecond } from "loopsie";

const initialState = {
    score: 0,
    height: 100
}

const gameLoop = new GameLoop(intialState, {
    msPerUdate: 10 // How often new state should be calculated
    maxFPS: 30     // How often subscribers are notifified of latest state
})

// Reduces height by 10 and increases the score by 1, spread over 1 second.
// Called continously until loop is stopped.
// `delta` indicates how many ms have passed since last call
gameLoop.addCallback((delta, state) => {
    return {
        height: state.height - perSecond(10, delta),
        score: state.score + perSecond(1, delta)
    }
})

gameLoop.addCallback((delta, state) => {
    if(state.height >= 0) {
        gameLoop.stop();
    }
})

// On every click, we want to increase the height by 3.
// `addRunOnce` is executed during the next loop
window.addEventListener("click", () => {
    gameLoop.addRunOnce((delta, state) => {
        return {
            ...state,
            height: state.height + 3
        }
    })
})

// Start the loop
gameLoop.start();

Keywords

FAQs

Package last updated on 03 Apr 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc