Events.onDestroy is a new signal that is dispatched whenever the parent is being destroyed. It's dispatched at the start of the destroy process, allowing you to perform any additional house cleaning needed (thanks @jonkelling #1084)

Group.onDestroy is a new signal that is dispatched whenever the Group is being destroyed. It's dispatched at the start of the destroy process, allowing you to perform any additional house cleaning needed (thanks @jonkelling #1084)
This commit is contained in:
photonstorm 2014-08-28 02:56:06 +01:00
parent 6b4510f693
commit fa45d7feff
8 changed files with 115 additions and 0 deletions

View file

@ -83,6 +83,8 @@ Version 2.1.0 - "Cairhien" - -in development-
* Phaser.Device.isAndroidStockBrowser will inform you if your game is running in a stock Android browser (rather than Chrome) where you may wish to scale down effects, disable WebGL, etc (thanks @lucbloom #989) * Phaser.Device.isAndroidStockBrowser will inform you if your game is running in a stock Android browser (rather than Chrome) where you may wish to scale down effects, disable WebGL, etc (thanks @lucbloom #989)
* Phaser.Camera has a new property `position` which is a Point object that allows you to get or set the camera position without having to read both the x and y values (thanks @Zielak #1015) * Phaser.Camera has a new property `position` which is a Point object that allows you to get or set the camera position without having to read both the x and y values (thanks @Zielak #1015)
* TileSprite now has the `alive` property, which should help with some Group operations (thanks @jonkelling #1085) * TileSprite now has the `alive` property, which should help with some Group operations (thanks @jonkelling #1085)
* Events.onDestroy is a new signal that is dispatched whenever the parent is being destroyed. It's dispatched at the start of the destroy process, allowing you to perform any additional house cleaning needed (thanks @jonkelling #1084)
* Group.onDestroy is a new signal that is dispatched whenever the Group is being destroyed. It's dispatched at the start of the destroy process, allowing you to perform any additional house cleaning needed (thanks @jonkelling #1084)
### Updates ### Updates

View file

@ -123,6 +123,11 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
*/ */
this.physicsBodyType = physicsBodyType; this.physicsBodyType = physicsBodyType;
/**
* @property {Phaser.Signal} onDestroy - This signal is dispatched when the parent is destoyed.
*/
this.onDestroy = new Phaser.Signal();
/** /**
* @property {string} _sortProperty - The property on which children are sorted. * @property {string} _sortProperty - The property on which children are sorted.
* @private * @private
@ -1688,6 +1693,8 @@ Phaser.Group.prototype.destroy = function (destroyChildren, soft) {
if (typeof destroyChildren === 'undefined') { destroyChildren = true; } if (typeof destroyChildren === 'undefined') { destroyChildren = true; }
if (typeof soft === 'undefined') { soft = false; } if (typeof soft === 'undefined') { soft = false; }
this.onDestroy.dispatch(this, destroyChildren, soft);
this.removeAll(destroyChildren); this.removeAll(destroyChildren);
this.cursor = null; this.cursor = null;

View file

@ -23,33 +23,114 @@
*/ */
Phaser.Events = function (sprite) { Phaser.Events = function (sprite) {
/**
* @property {Phaser.Sprite} parent - The Sprite that owns these events.
*/
this.parent = sprite; this.parent = sprite;
/**
* @property {Phaser.Signal} onAddedToGroup - This signal is dispatched when the parent is added to a new Group.
*/
this.onAddedToGroup = new Phaser.Signal(); this.onAddedToGroup = new Phaser.Signal();
/**
* @property {Phaser.Signal} onRemovedFromGroup - This signal is dispatched when the parent is removed from a Group.
*/
this.onRemovedFromGroup = new Phaser.Signal(); this.onRemovedFromGroup = new Phaser.Signal();
/**
* @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.
*/
this.onKilled = new Phaser.Signal(); this.onKilled = new Phaser.Signal();
/**
* @property {Phaser.Signal} onRevived - This signal is dispatched when the parent is revived.
*/
this.onRevived = new Phaser.Signal(); this.onRevived = new Phaser.Signal();
/**
* @property {Phaser.Signal} onOutOfBounds - This signal is dispatched when the parent leaves the world bounds (only if Sprite.checkWorldBounds is true).
*/
this.onOutOfBounds = new Phaser.Signal(); this.onOutOfBounds = new Phaser.Signal();
/**
* @property {Phaser.Signal} onEnterBounds - This signal is dispatched when the parent returns within the world bounds (only if Sprite.checkWorldBounds is true).
*/
this.onEnterBounds = new Phaser.Signal(); this.onEnterBounds = new Phaser.Signal();
/**
* @property {Phaser.Signal} onInputOver - This signal is dispatched if the parent is inputEnabled and receives an over event from a Pointer.
* @default null
*/
this.onInputOver = null; this.onInputOver = null;
/**
* @property {Phaser.Signal} onInputOut - This signal is dispatched if the parent is inputEnabled and receives an out event from a Pointer.
* @default null
*/
this.onInputOut = null; this.onInputOut = null;
/**
* @property {Phaser.Signal} onInputDown - This signal is dispatched if the parent is inputEnabled and receives a down event from a Pointer.
* @default null
*/
this.onInputDown = null; this.onInputDown = null;
/**
* @property {Phaser.Signal} onInputUp - This signal is dispatched if the parent is inputEnabled and receives an up event from a Pointer.
* @default null
*/
this.onInputUp = null; this.onInputUp = null;
/**
* @property {Phaser.Signal} onDragStart - This signal is dispatched if the parent is inputEnabled and receives a drag start event from a Pointer.
* @default null
*/
this.onDragStart = null; this.onDragStart = null;
/**
* @property {Phaser.Signal} onDragStop - This signal is dispatched if the parent is inputEnabled and receives a drag stop event from a Pointer.
* @default null
*/
this.onDragStop = null; this.onDragStop = null;
/**
* @property {Phaser.Signal} onAnimationStart - This signal is dispatched when the parent has an animation that is played.
* @default null
*/
this.onAnimationStart = null; this.onAnimationStart = null;
/**
* @property {Phaser.Signal} onAnimationComplete - This signal is dispatched when the parent has an animation that finishes playing.
* @default null
*/
this.onAnimationComplete = null; this.onAnimationComplete = null;
/**
* @property {Phaser.Signal} onAnimationLoop - This signal is dispatched when the parent has an animation that loops playback.
* @default null
*/
this.onAnimationLoop = null; this.onAnimationLoop = null;
}; };
Phaser.Events.prototype = { Phaser.Events.prototype = {
/**
* Removes all events.
*
* @method destroy
*/
destroy: function () { destroy: function () {
this.parent = null; this.parent = null;
this.onDestroy.dispose();
this.onAddedToGroup.dispose(); this.onAddedToGroup.dispose();
this.onRemovedFromGroup.dispose(); this.onRemovedFromGroup.dispose();
this.onKilled.dispose(); this.onKilled.dispose();

View file

@ -386,6 +386,11 @@ Phaser.Image.prototype.destroy = function(destroyChildren) {
this._cache[8] = 1; this._cache[8] = 1;
if (this.events)
{
this.events.onDestroy.dispatch(this);
}
if (this.parent) if (this.parent)
{ {
if (this.parent instanceof Phaser.Group) if (this.parent instanceof Phaser.Group)

View file

@ -411,6 +411,11 @@ Phaser.Rope.prototype.destroy = function(destroyChildren) {
this._cache[8] = 1; this._cache[8] = 1;
if (this.events)
{
this.events.onDestroy.dispatch(this);
}
if (this.filters) if (this.filters)
{ {
this.filters = null; this.filters = null;

View file

@ -644,6 +644,11 @@ Phaser.Sprite.prototype.destroy = function(destroyChildren) {
this._cache[8] = 1; this._cache[8] = 1;
if (this.events)
{
this.events.onDestroy.dispatch(this);
}
if (this.parent) if (this.parent)
{ {
if (this.parent instanceof Phaser.Group) if (this.parent instanceof Phaser.Group)

View file

@ -220,6 +220,11 @@ Phaser.Text.prototype.destroy = function (destroyChildren) {
this._cache[8] = 1; this._cache[8] = 1;
if (this.events)
{
this.events.onDestroy.dispatch(this);
}
if (this.parent) if (this.parent)
{ {
if (this.parent instanceof Phaser.Group) if (this.parent instanceof Phaser.Group)

View file

@ -442,6 +442,11 @@ Phaser.TileSprite.prototype.destroy = function(destroyChildren) {
this._cache[8] = 1; this._cache[8] = 1;
if (this.events)
{
this.events.onDestroy.dispatch(this);
}
if (this.filters) if (this.filters)
{ {
this.filters = null; this.filters = null;