Socket
Socket
Sign inDemoInstall

game-time-accumulator

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

game-time-accumulator

game-time-accumulator class for creating a game


Version published
Weekly downloads
1
Maintainers
2
Weekly downloads
 
Created
Source

npm version

game-time-accumulator

A great class to manage updates to your own game using time accumulator principle. Works on browser + NodeJS (check this for compability table)

Install

npm install game-time-accumulator or bower install game-time-accumulator.

Use

var GameTimeAccumulator = require('game-time-accumulator');

var canvas = document.getElementById('game-canvas');
var ctx = canvas.getContext('2d');

// Happens exactly in a loop you define
var stepFn = function(){
  player.move();
}

// Happen every requestAnimationFrame
var drawFn = function(){
  // Clear canvas before each fraw
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  player.draw(ctx);
}

var game = new GameTimeAccumulator(stepFn, drawFn, 200);
game.start();

Parameters

stepFn - (Function, default noop) - Run every step loop (you define the time)

drawFn - (Function, default noop) - Run every requestAnimationFrame loop (system defines the time)

stepSize - (Number, default 16 - ~60fps) - Milliseconds of step to loop

Functions

start() - Starts the game

stop() - Stops the game

Keywords

FAQs

Package last updated on 07 Oct 2017

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