1.0.2 • Published 10 years ago
@vaalentin/game-loop v1.0.2
Game loop
Simple game loop.
Installation
$ npm install --save @vaalentin/game-loopUsage
import GameLoop from '@vaalentin/game-loop';
const loop = new GameLoop(30);
loop.on('init', () => {
// called once
});
loop.on('update', dt => {
// called 30 times per second
});
loop.on('render', dt => {
// called as fast as possible, usually 60 times a sec
});API
GameLoop inherits from EventDispatcher.
loop = new GameLoop(fps, speed)
Where fps is a number that dictates how many times per second the update will be called.
This is used to get a constant timestep (default is 60).
speed is a number from (usually from 0 to 2), to increase/reduce the timestep (default is 1).
loop.start()
Start loop.
loop.stop()
Stop loop.
loop.dispose()
Delete instance. Calls loop.stop().
Events
initCalled once, when the loop starts for the first time.startCalled every time the loop starts.stopCalled every time the loop stops.updateCalled at a constant interval, given by thefpsparameter.renderCalled as fast asrequestAnimationFramecan go.
License
MIT, see LICENSE.md for more details.