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 the parent is added to a new Group.
- Source code: gameobjects/components/Events.js (Line 80)
-
onAnimationComplete : Phaser.Signal
-
This signal is dispatched when the parent has an animation that finishes playing.
- Source code: gameobjects/components/Events.js (Line 160)
-
onAnimationLoop : Phaser.Signal
-
This signal is dispatched when the parent has an animation that loops playback.
- Source code: gameobjects/components/Events.js (Line 165)
-
onAnimationStart : Phaser.Signal
-
This signal is dispatched when the parent has an animation that is played.
- Source code: gameobjects/components/Events.js (Line 155)
-
onDestroy : Phaser.Signal
-
This signal is dispatched when the parent is destroyed.
- Source code: gameobjects/components/Events.js (Line 95)
-
onDragStart : Phaser.Signal
-
This signal is dispatched if the parent is inputEnabled and receives a drag start event from a Pointer.
- Source code: gameobjects/components/Events.js (Line 140)
-
onDragStop : Phaser.Signal
-
This signal is dispatched if the parent is inputEnabled and receives a drag stop event from a Pointer.
- Source code: gameobjects/components/Events.js (Line 150)
-
onDragUpdate : Phaser.Signal
-
This signal is dispatched if the parent is inputEnabled and receives a drag update event from a Pointer.
- Source code: gameobjects/components/Events.js (Line 145)
-
onEnterBounds : Phaser.Signal
-
This signal is dispatched when the parent returns within the world bounds (only if Sprite.checkWorldBounds is true).
- Source code: gameobjects/components/Events.js (Line 115)
-
onInputDown : Phaser.Signal
-
This signal is dispatched if the parent is inputEnabled and receives a down event from a Pointer.
- Source code: gameobjects/components/Events.js (Line 130)
-
onInputOut : Phaser.Signal
-
This signal is dispatched if the parent is inputEnabled and receives an out event from a Pointer.
- Source code: gameobjects/components/Events.js (Line 125)
-
onInputOver : Phaser.Signal
-
This signal is dispatched if the parent is inputEnabled and receives an over event from a Pointer.
- Source code: gameobjects/components/Events.js (Line 120)
-
onInputUp : Phaser.Signal
-
This signal is dispatched if the parent is inputEnabled and receives an up event from a Pointer.
- Source code: gameobjects/components/Events.js (Line 135)
-
onKilled : Phaser.Signal
-
This signal is dispatched when the parent is killed.
- Source code: gameobjects/components/Events.js (Line 100)
-
onOutOfBounds : Phaser.Signal
-
This signal is dispatched when the parent leaves the world bounds (only if Sprite.checkWorldBounds is true).
- Source code: gameobjects/components/Events.js (Line 110)
-
onRemovedFromGroup : Phaser.Signal
-
This signal is dispatched when the parent is removed from a Group.
- Source code: gameobjects/components/Events.js (Line 85)
-
onRemovedFromWorld : Phaser.Signal
-
This signal is dispatched if this item or any of its parents are removed from the game world.
- Source code: gameobjects/components/Events.js (Line 90)
-
onRevived : Phaser.Signal
-
This signal is dispatched when the parent is revived.
- Source code: gameobjects/components/Events.js (Line 105)
-
parent : Phaser.Sprite
-
The Sprite that owns these events.
- Source code: gameobjects/components/Events.js (Line 35)
Public Methods
-
destroy()
-
Removes all events.
- Source code: gameobjects/components/Events.js (Line 43)