🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@callmehiphop/ticker

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@callmehiphop/ticker

Simple event-based fixed-rate game loop.

0.2.1
latest
Source
npm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

ticker

Simple event based game loop based on the Game Programming Patterns Game Loop chapter.

Install

$ npm install --save @callmehiphop/ticker

Usage

const Ticker = require('@callmehiphop/ticker');
const ticker = new Ticker();

ticker.on('update', (dt) => {
  // update all the things!
});

ticker.on('render', () => {
  // render all the things!
});

// stop the ticker
ticker.stop();

// resume the ticker
ticker.resume();

API

new Ticker(el, [fps])

el

Type: canvas

HTML element to be passed into requestAnimationFrame - presumably canvas.

fps

Type: number
Default: 60

Desired frames per second, this will alter how often the update event is fired.

const canvas = document.getElementById('my-canvas');
const ticker = new Ticker(canvas, 30);

ticker.on('update', handler)

Indicates models should be updated with provided delta time.

handler(dt)

Type: function

ticker.on('update', (dt) => {
  // Update all your models.
});

ticker.on('render', handler)

Indicates that you should draw the current state of your models.

handler(frameStep)

frameStep is how far into the current frame we are.

Type: function

ticker.on('render', (frameStep) => {
  // Render all your models.
});

ticker.stop()

Stops the ticker.

ticker.stop();

ticker.resume()

Resumes the ticker.

ticker.resume();

License

MIT

Keywords

game

FAQs

Package last updated on 06 Oct 2016

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