1.3.0 • Published 7 years ago

game-time-accumulator v1.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

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

1.3.0

7 years ago

1.2.2

9 years ago

1.0.0

9 years ago