Constructor
new Hummingbird(handler, argsopt)
A Hummingbird is a single object that holds a single method to be called on a set iteration speed.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
handler |
function | The method called on each tick based on speed |
||
args |
object |
<optional> |
Optional parameters |
|
speed |
number |
<optional> |
30 | The frequency that the Hummingbird's handler will be called |
speedIn |
string |
<optional> |
FLAPS | How to interpret the |
scope |
* |
<optional> |
What |
|
lifeSpan |
number |
<optional> |
Length of time the handler will be active |
|
lifeSpanIn |
string |
<optional> |
SECONDS | How to interpret |
onComplete |
function |
<optional> |
Called when |
|
onCompleteParams |
array |
<optional> |
Parameters passed through |
Example
import { Hummingbird } from 'hummingbird'
function foo() { ... }
function bar() { ... }
// basic creation, using default speed (30 fps)
const fooBird = new Hummingbird(foo)
// complex creation, things to note:
// - 'new' is optional
// - use 'args' object to pass in optional parameters
// - does not require being assinged to variable
Hummingbird(bar, {
// interpret speed in seconds
speedIn: SECONDS,
// will call handler once every 1.3 seconds
speed: 1.3,
// interpret lifeSpan in flaps
lifeSpanIn: FLAPS,
// will call handler only 3 times
lifeSpan: 3,
// if lifeSpan, add a handler
onComplete: function(a, b) {
// a = true, b = 'ruh'
},
// provide params to the handler
onCompleteParams: [true, 'ruh']
})
Methods
release() → {Hummingbird}
Will release (remove) this Hummingbird instance from the engine. Note that this does NOT destroy itself and any external variables holding reference to the instance are still valid. Be mindful of assigning instances to variables repeatedly as it can cause a bloat without allowing for proper garbage collection.
Itself for method chaining
Example
// continued from Constructor example
foobird.release()
sleep() → {Hummingbird}
Will sleep (pause) this Hummingbird instance so it will not be called on iterations. If this is the only and/or last active instance, the entire engine will stop running.
Itself for method chaining
Example
// continued from Constructor example
foobird.sleep()
speed(val) → {Hummingbird}
The iteration speed of the instance.
Parameters:
Name | Type | Description |
---|---|---|
val |
number |
Itself for method chaining
Example
// continued from Constructor example
// changes the speed from the default 30 fps to 24 fps
foobird.speed(24)
toString() → {String}
The string representation of the Hummingbird
wake() → {Hummingbird}
Will wake (resume) this Hummingbird instance so it will not be called on iterations. If this instance has been released, calling this will act as if creating a new instance without the memory bloat of actually creating. This includes reseting lifeSpan to run again. This will activate the entire engine if it is not already running.
Itself for method chaining
Example
// continued from Constructor example
foobird.wake()