tiny-ticker v0.0.2
tiny ticker

A ticker utility for time-sensitive loops in Node.js, written in TypeScript. Not currently supported in browsers.
Installation
For Node.js or webpack projects, install with the NPM package manager:
npm install --save tiny-ticker
Usage
// commonjs module
const { Ticker } = require('tiny-ticker')
// esmodules
import { Ticker } from 'tiny-ticker'
// in the browser
const { Ticker } = window.TinyTicker
const ticker = new Ticker(50) // create a Ticker that ticks every 50ms
ticker.on('start', () => {/* ... */}) // fired when the ticker starts
ticker.on('tick', () => {/* ... */}) // fired for every tick, run your update loop here
ticker.on('stop', () => {/* ... */}) // fired when the ticker stops
ticker.start() // start ticker
/* ... */
ticker.stop() // stop ticker
For detailed documentation on each of these methods, check the API documention below.
API
Ticker ⇐ EventEmitter<ITickerEvents>
A Ticker controller.
Kind: global class
Extends: EventEmitter<ITickerEvents>
- Ticker ⇐ EventEmitter<ITickerEvents>
new Ticker(interval)
Create a Ticker.
Param | Type | Default | Description |
---|---|---|---|
interval | number | 0 | Interval (or tick speed) in milliseconds to run the Ticker at |
ticker.start() ⇒ void
Start the Ticker, immediately emits a start
event.
Kind: instance method of Ticker
Emits: start
Access: public
ticker.stop() ⇒ void
Start the Ticker, immediately emits a stop
event.
Kind: instance method of Ticker
Emits: stop
Access: public
"start"
Fires when the Ticker is started.
Kind: event emitted by Ticker
"stop"
Fires when the Ticker is stopped.
Kind: event emitted by Ticker
"tick"
Fires on every tick.
Kind: event emitted by Ticker
Properties
Name | Type | Description |
---|---|---|
tickCount | number | Current tick |
delta | number | Current delta |