gloop
v0.0.2
Published
Fixed-timestep, deterministic game loop manager that supports arbitrary time-scaling.
Downloads
3
Maintainers
Readme
gloop
Gloop is a fixed timestep game loop manager,
decoupling frame
events from game tick
events.
This allows for deterministic behavior even with variable framerates.
NOTE: This has not been battle tested yet; use at your own risk. (And please report issues)
var gloop = require('gloop')();
// Or...
var gloop = require('gloop')({
ticksPerSecond: 300
});
// gloop mostly emits events
gloop.on('tick', function (dt) {
// Update logic goes here
console.log('In-game milliseconds since last tick:', dt);
});
gloop.on('frame', function (t) {
// Render logic goes here
// `t` is a value between 0 and 1 representing the current
// temporal position between ticks; use this to interpolate
// rendered motion, if you want. This is especially useful
// if you're using gloop.timeScale for dramatic slow-motion
// effects.
console.log('Delta between ticks:', t);
});
gloop.on('start', function () {
console.log('game loop started');
});
gloop.on('stop', function () {
console.log('game loop stopped');
});
// Begin/resume looping:
gloop.start();
// Run things in slow-motion:
gloop.timeScale = 0.5;
// Or high-speed:
gloop.timeScale = 2;
// Pause/stop looping:
gloop.stop();
License
MIT
Install
npm install gloop --save