add(listener, listenerContext, priority, args) → {Phaser.SignalBinding}
Add an event listener for this signal.
An event listener is a callback with a related context and priority.
You can optionally provide extra arguments which will be passed to the callback after any internal parameters.
For example: Phaser.Key.onDown
when dispatched will send the Phaser.Key object that caused the signal as the first parameter.
Any arguments you've specified after priority
will be sent as well:
fireButton.onDown.add(shoot, this, 0, 'lazer', 100);
When onDown dispatches it will call the shoot
callback passing it: Phaser.Key, 'lazer', 100
.
Where the first parameter is the one that Key.onDown dispatches internally and 'lazer',
and the value 100 were the custom arguments given in the call to 'add'.
Parameters
Name | Type | Argument | Default | Description |
---|---|---|---|---|
listener | function | The function to call when this Signal is dispatched. | ||
listenerContext | object | <optional> | The context under which the listener will be executed (i.e. the object that should represent the | |
priority | number | <optional> | The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added (default = 0) | |
args | any | <optional> <repeatable> | (none) | Additional arguments to pass to the callback (listener) function. They will be appended after any arguments usually dispatched. |
Returns
An Object representing the binding between the Signal and listener.
- Source code: core/Signal.js (Line 232)
Please login to continue.