2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2014-02-05 05:54:25 +00:00
|
|
|
* @copyright 2014 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2013-09-08 21:38:19 +00:00
|
|
|
/**
|
2014-09-16 16:35:08 +00:00
|
|
|
* The Events component is a collection of events fired by the parent game object.
|
2013-11-28 15:57:09 +00:00
|
|
|
*
|
|
|
|
* For example to tell when a Sprite has been added to a new group:
|
|
|
|
*
|
2014-03-03 16:05:55 +00:00
|
|
|
* `sprite.events.onAddedToGroup.add(yourFunction, this);`
|
2013-11-28 15:57:09 +00:00
|
|
|
*
|
|
|
|
* Where `yourFunction` is the function you want called when this event occurs.
|
|
|
|
*
|
|
|
|
* Note that the Input related events only exist if the Sprite has had `inputEnabled` set to `true`.
|
|
|
|
*
|
2014-09-16 16:35:08 +00:00
|
|
|
* @class Phaser.Events
|
2013-10-01 12:54:29 +00:00
|
|
|
* @constructor
|
2014-10-21 21:43:42 +00:00
|
|
|
* @param {Phaser.Sprite} sprite - A reference to the Sprite that owns this Events object.
|
2013-09-08 21:38:19 +00:00
|
|
|
*/
|
|
|
|
Phaser.Events = function (sprite) {
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-08-28 01:56:06 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Sprite} parent - The Sprite that owns these events.
|
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this.parent = sprite;
|
2014-02-05 02:39:03 +00:00
|
|
|
|
2014-08-28 01:56:06 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onAddedToGroup - This signal is dispatched when the parent is added to a new Group.
|
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this.onAddedToGroup = new Phaser.Signal();
|
2014-08-28 01:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onRemovedFromGroup - This signal is dispatched when the parent is removed from a Group.
|
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this.onRemovedFromGroup = new Phaser.Signal();
|
2014-08-28 01:56:06 +00:00
|
|
|
|
2014-10-28 01:48:42 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onRemovedFromWorld - This signal is dispatched if this item or any of its parents are removed from the game world.
|
|
|
|
*/
|
|
|
|
this.onRemovedFromWorld = new Phaser.Signal();
|
|
|
|
|
2014-08-28 01:56:06 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onDestroy - This signal is dispatched when the parent is destoyed.
|
|
|
|
*/
|
|
|
|
this.onDestroy = new Phaser.Signal();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onKilled - This signal is dispatched when the parent is killed.
|
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this.onKilled = new Phaser.Signal();
|
2014-08-28 01:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onRevived - This signal is dispatched when the parent is revived.
|
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this.onRevived = new Phaser.Signal();
|
2014-08-28 01:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onOutOfBounds - This signal is dispatched when the parent leaves the world bounds (only if Sprite.checkWorldBounds is true).
|
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this.onOutOfBounds = new Phaser.Signal();
|
2014-08-28 01:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onEnterBounds - This signal is dispatched when the parent returns within the world bounds (only if Sprite.checkWorldBounds is true).
|
|
|
|
*/
|
2014-03-19 04:16:37 +00:00
|
|
|
this.onEnterBounds = new Phaser.Signal();
|
2013-09-08 21:38:19 +00:00
|
|
|
|
2014-08-28 01:56:06 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onInputOver - This signal is dispatched if the parent is inputEnabled and receives an over event from a Pointer.
|
|
|
|
* @default null
|
|
|
|
*/
|
2013-09-08 21:38:19 +00:00
|
|
|
this.onInputOver = null;
|
2014-08-28 01:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onInputOut - This signal is dispatched if the parent is inputEnabled and receives an out event from a Pointer.
|
|
|
|
* @default null
|
|
|
|
*/
|
2013-09-08 21:38:19 +00:00
|
|
|
this.onInputOut = null;
|
2014-08-28 01:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onInputDown - This signal is dispatched if the parent is inputEnabled and receives a down event from a Pointer.
|
|
|
|
* @default null
|
|
|
|
*/
|
2013-09-08 21:38:19 +00:00
|
|
|
this.onInputDown = null;
|
2014-08-28 01:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onInputUp - This signal is dispatched if the parent is inputEnabled and receives an up event from a Pointer.
|
|
|
|
* @default null
|
|
|
|
*/
|
2013-09-08 21:38:19 +00:00
|
|
|
this.onInputUp = null;
|
2014-08-28 01:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onDragStart - This signal is dispatched if the parent is inputEnabled and receives a drag start event from a Pointer.
|
|
|
|
* @default null
|
|
|
|
*/
|
2013-09-08 21:38:19 +00:00
|
|
|
this.onDragStart = null;
|
2014-08-28 01:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onDragStop - This signal is dispatched if the parent is inputEnabled and receives a drag stop event from a Pointer.
|
|
|
|
* @default null
|
|
|
|
*/
|
2013-09-08 21:38:19 +00:00
|
|
|
this.onDragStop = null;
|
|
|
|
|
2014-08-28 01:56:06 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onAnimationStart - This signal is dispatched when the parent has an animation that is played.
|
|
|
|
* @default null
|
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this.onAnimationStart = null;
|
2014-08-28 01:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onAnimationComplete - This signal is dispatched when the parent has an animation that finishes playing.
|
|
|
|
* @default null
|
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this.onAnimationComplete = null;
|
2014-08-28 01:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onAnimationLoop - This signal is dispatched when the parent has an animation that loops playback.
|
|
|
|
* @default null
|
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this.onAnimationLoop = null;
|
2013-09-10 19:40:34 +00:00
|
|
|
|
2013-10-13 00:29:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.Events.prototype = {
|
|
|
|
|
2014-08-28 01:56:06 +00:00
|
|
|
/**
|
|
|
|
* Removes all events.
|
|
|
|
*
|
2014-11-25 00:20:41 +00:00
|
|
|
* @method Phaser.Events#destroy
|
2014-08-28 01:56:06 +00:00
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
destroy: function () {
|
2013-10-13 00:29:57 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
this.parent = null;
|
2014-08-28 01:56:06 +00:00
|
|
|
|
|
|
|
this.onDestroy.dispose();
|
2013-11-25 03:13:04 +00:00
|
|
|
this.onAddedToGroup.dispose();
|
|
|
|
this.onRemovedFromGroup.dispose();
|
2014-10-28 01:48:42 +00:00
|
|
|
this.onRemovedFromWorld.dispose();
|
2013-11-25 03:13:04 +00:00
|
|
|
this.onKilled.dispose();
|
|
|
|
this.onRevived.dispose();
|
|
|
|
this.onOutOfBounds.dispose();
|
2013-10-13 00:29:57 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
if (this.onInputOver)
|
|
|
|
{
|
|
|
|
this.onInputOver.dispose();
|
|
|
|
this.onInputOut.dispose();
|
|
|
|
this.onInputDown.dispose();
|
|
|
|
this.onInputUp.dispose();
|
|
|
|
this.onDragStart.dispose();
|
|
|
|
this.onDragStop.dispose();
|
|
|
|
}
|
2013-10-13 00:29:57 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
if (this.onAnimationStart)
|
|
|
|
{
|
|
|
|
this.onAnimationStart.dispose();
|
|
|
|
this.onAnimationComplete.dispose();
|
|
|
|
this.onAnimationLoop.dispose();
|
|
|
|
}
|
2013-10-13 00:29:57 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
}
|
2013-10-13 00:29:57 +00:00
|
|
|
|
2013-12-30 16:54:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.Events.prototype.constructor = Phaser.Events;
|