new Events(sprite)
The Events component is a collection of events fired by the parent Game Object.
Phaser uses what are known as 'Signals' for all event handling. All of the events in
this class are signals you can subscribe to, much in the same way you'd "listen" for
an event.
For example to tell when a Sprite has been added to a new group, you can bind a function
to the onAddedToGroup
signal:
sprite.events.onAddedToGroup.add(yourFunction, this);
Where yourFunction
is the function you want called when this event occurs.
For more details about how signals work please see the Phaser.Signal class.
The Input-related events will only be dispatched if the Sprite has had inputEnabled
set to true
and the Animation-related events only apply to game objects with animations like Phaser.Sprite.
Parameters
Name | Type | Description |
---|---|---|
sprite |
Phaser.Sprite | A reference to the game object / Sprite that owns this Events object. |
- Source code: gameobjects/components/Events.js (Line 30)
Public Properties
-
onAddedToGroup : Phaser.Signal
-
This signal is dispatched when this Game Object is added to a new Group.
It is sent two arguments:
{any} The Game Object that was added to the Group.
{Phaser.Group} The Group it was added to.- Source code: gameobjects/components/Events.js (Line 84)
-
onAnimationComplete : Phaser.Signal
-
This signal is dispatched if the Game Object has the AnimationManager component,
and an Animation has been stopped (viaanimation.stop()
and thedispatchComplete
argument has been set.
You can also listen toAnimation.onComplete
rather than via the Game Objects events.
It is sent two arguments:
{any} The Game Object that received the event.
{Phaser.Animation} The Phaser.Animation that was stopped.- Source code: gameobjects/components/Events.js (Line 249)
-
onAnimationLoop : Phaser.Signal
-
This signal is dispatched if the Game Object has the AnimationManager component,
and an Animation has looped playback.
You can also listen toAnimation.onLoop
rather than via the Game Objects events.
It is sent two arguments:
{any} The Game Object that received the event.
{Phaser.Animation} The Phaser.Animation that looped.- Source code: gameobjects/components/Events.js (Line 260)
-
onAnimationStart : Phaser.Signal
-
This signal is dispatched if the Game Object has the AnimationManager component,
and an Animation has been played.
You can also listen toAnimation.onStart
rather than via the Game Objects events.
It is sent two arguments:
{any} The Game Object that received the event.
{Phaser.Animation} The Phaser.Animation that was started.- Source code: gameobjects/components/Events.js (Line 238)
-
onDestroy : Phaser.Signal
-
This signal is dispatched when the Game Object is destroyed.
This happens whenSprite.destroy()
is called, orGroup.destroy()
withdestroyChildren
set to true.
It is sent one argument:
{any} The Game Object that was destroyed.- Source code: gameobjects/components/Events.js (Line 109)
-
onDragStart : Phaser.Signal
-
This signal is dispatched if the Game Object has been
inputEnabled
andenableDrag
has been set.
It is sent when a Phaser.Pointer starts to drag the Game Object, taking into consideration the various
drag limitations that may be set.
It is sent four arguments:
{any} The Game Object that received the event.
{Phaser.Pointer} The Phaser.Pointer object that caused the event.
{number} The x coordinate that the drag started from.
{number} The y coordinate that the drag started from.- Source code: gameobjects/components/Events.js (Line 202)
-
onDragStop : Phaser.Signal
-
This signal is dispatched if the Game Object has been
inputEnabled
andenableDrag
has been set.
It is sent when a Phaser.Pointer stops dragging the Game Object.
It is sent two arguments:
{any} The Game Object that received the event.
{Phaser.Pointer} The Phaser.Pointer object that caused the event.- Source code: gameobjects/components/Events.js (Line 227)
-
onDragUpdate : Phaser.Signal
-
This signal is dispatched if the Game Object has been
inputEnabled
andenableDrag
has been set.
It is sent when a Phaser.Pointer is actively dragging the Game Object.
Be warned: This is a high volume Signal. Be careful what you bind to it.
It is sent six arguments:
{any} The Game Object that received the event.
{Phaser.Pointer} The Phaser.Pointer object that caused the event.
{number} The new x coordinate of the Game Object.
{number} The new y coordinate of the Game Object.
{Phaser.Point} A Point object that contains the point the Game Object was snapped to, ifsnapOnDrag
has been enabled.
{boolean} ThefromStart
boolean, indicates if this is the first update immediately after the drag has started.- Source code: gameobjects/components/Events.js (Line 217)
-
onEnterBounds : Phaser.Signal
-
This signal is dispatched when the Game Object returns within the Phaser.World bounds, having previously been outside of them.
This signal is only ifSprite.checkWorldBounds
is set totrue
.
It is sent one argument:
{any} The Game Object that entered the World bounds.- Source code: gameobjects/components/Events.js (Line 146)
-
onInputDown : Phaser.Signal
-
This signal is dispatched if the Game Object has
inputEnabled
set totrue
,
and receives a down event from a Phaser.Pointer. This effectively means the Pointer has been
pressed down (but not yet released) on the Game Object.
It is sent two arguments:
{any} The Game Object that received the event.
{Phaser.Pointer} The Phaser.Pointer object that caused the event.- Source code: gameobjects/components/Events.js (Line 177)
-
onInputOut : Phaser.Signal
-
This signal is dispatched if the Game Object has
inputEnabled
set totrue
,
and receives an out event from a Phaser.Pointer, which was previously over it.
It is sent two arguments:
{any} The Game Object that received the event.
{Phaser.Pointer} The Phaser.Pointer object that caused the event.- Source code: gameobjects/components/Events.js (Line 166)
-
onInputOver : Phaser.Signal
-
This signal is dispatched if the Game Object has
inputEnabled
set totrue
,
and receives an over event from a Phaser.Pointer.
It is sent two arguments:
{any} The Game Object that received the event.
{Phaser.Pointer} The Phaser.Pointer object that caused the event.- Source code: gameobjects/components/Events.js (Line 156)
-
onInputUp : Phaser.Signal
-
This signal is dispatched if the Game Object has
inputEnabled
set totrue
,
and receives an up event from a Phaser.Pointer. This effectively means the Pointer had been
pressed down, and was then released on the Game Object.
It is sent three arguments:
{any} The Game Object that received the event.
{Phaser.Pointer} The Phaser.Pointer object that caused the event.
{boolean} isOver - Is the Pointer still over the Game Object?- Source code: gameobjects/components/Events.js (Line 189)
-
onKilled : Phaser.Signal
-
This signal is dispatched when the Game Object is killed.
This happens whenSprite.kill()
is called.
Please understand the difference betweenkill
anddestroy
by looking at their respective methods.
It is sent one argument:
{any} The Game Object that was killed.- Source code: gameobjects/components/Events.js (Line 119)
-
onOutOfBounds : Phaser.Signal
-
This signal is dispatched when the Game Object leaves the Phaser.World bounds.
This signal is only ifSprite.checkWorldBounds
is set totrue
.
It is sent one argument:
{any} The Game Object that left the World bounds.- Source code: gameobjects/components/Events.js (Line 137)
-
onRemovedFromGroup : Phaser.Signal
-
This signal is dispatched when the Game Object is removed from a Group.
It is sent two arguments:
{any} The Game Object that was removed from the Group.
{Phaser.Group} The Group it was removed from.- Source code: gameobjects/components/Events.js (Line 93)
-
onRemovedFromWorld : Phaser.Signal
- This method is deprecated and should not be used. It may be removed in the future.
- Deprecated:
- Yes
- Source code: gameobjects/components/Events.js (Line 100)
-
onRevived : Phaser.Signal
-
This signal is dispatched when the Game Object is revived from a previously killed state.
This happens whenSprite.revive()
is called.
It is sent one argument:
{any} The Game Object that was revived.- Source code: gameobjects/components/Events.js (Line 128)
-
parent : Phaser.Sprite
-
The Sprite that owns these events.
- Source code: gameobjects/components/Events.js (Line 35)
This Signal is never used internally by Phaser and is now deprecated.
Public Methods
-
destroy()
-
Removes all events.
- Source code: gameobjects/components/Events.js (Line 43)