World.destroy incorrectly clashed with the Group.destroy method it over-rode, renamed to World.shutdown and updated StateManager accordingly.

World.shutdown now removes all children iteratively, calling destroy on each one, ultimately performing a soft reset of the World.
Objects with a scale.x or y of 0 are no longer considered valid for input (fix #602)
InputHandler will set the browser pointer back to default if destroyed while over (fix #602)
Group.destroy has a new parameter: `soft`. A soft destruction won't remove the Group from its parent or null game references. Default is `false`.
InputHandler.validForInput is a new method that checks if the handler and its owner should be considered for Pointer input handling or not.
Group.replace will now return the old child, the one that was replaced in the Group.
This commit is contained in:
photonstorm 2014-03-19 00:54:49 +00:00
parent 8010d245f1
commit 11fdd62436
7 changed files with 81 additions and 13 deletions

View file

@ -69,6 +69,10 @@ Bug Fixes
* Button.onInputUpHandler wouldn't set an upFrame for a frame ID of zero, made the check more strict.
* Fixed the Loader.preloadSprite crop effect on WebGL.
* Fixed Grunt script that stopped the P2 constraint classes from building properly.
* World.destroy incorrectly clashed with the Group.destroy method it over-rode, renamed to World.shutdown and updated StateManager accordingly.
* World.shutdown now removes all children iteratively, calling destroy on each one, ultimately performing a soft reset of the World.
* Objects with a scale.x or y of 0 are no longer considered valid for input (fix #602)
* InputHandler will set the browser pointer back to default if destroyed while over (fix #602)
Updated:
@ -81,6 +85,9 @@ Updated:
* Lots of TypeScript definitions updates (thanks as always to clark for these)
* Removed Device.patchAndroidClearRectBug as it's no longer used internally.
* Math.wrapAngle now supports radians (thanks Cryszon, #597)
* Group.replace will now return the old child, the one that was replaced in the Group.
* Group.destroy has a new parameter: `soft`. A soft destruction won't remove the Group from its parent or null game references. Default is `false`.
* InputHandler.validForInput is a new method that checks if the handler and its owner should be considered for Pointer input handling or not.
New Features:

View file

@ -561,6 +561,7 @@ Phaser.Group.prototype.getIndex = function (child) {
* @method Phaser.Group#replace
* @param {*} oldChild - The child in this Group that will be replaced.
* @param {*} newChild - The child to be inserted into this Group.
* @return {*} Returns the oldChild that was replaced within this Group.
*/
Phaser.Group.prototype.replace = function (oldChild, newChild) {
@ -579,9 +580,13 @@ Phaser.Group.prototype.replace = function (oldChild, newChild) {
}
}
this.removeChild(oldChild);
var temp = oldChild;
this.remove(temp);
this.addAt(newChild, index);
return temp;
}
}
@ -1420,12 +1425,14 @@ Phaser.Group.prototype.removeBetween = function (startIndex, endIndex) {
*
* @method Phaser.Group#destroy
* @param {boolean} [destroyChildren=true] - Should every child of this Group have its destroy method called?
* @param {boolean} [soft=false] - A 'soft destroy' (set to true) doesn't remove this Group from its parent or null the game reference. Set to false and it does.
*/
Phaser.Group.prototype.destroy = function (destroyChildren) {
Phaser.Group.prototype.destroy = function (destroyChildren, soft) {
if (this.game === null) { return; }
if (typeof destroyChildren === 'undefined') { destroyChildren = true; }
if (typeof soft === 'undefined') { soft = false; }
if (destroyChildren)
{
@ -1446,14 +1453,17 @@ Phaser.Group.prototype.destroy = function (destroyChildren) {
this.removeAll();
}
this.parent.removeChild(this);
this.game = null;
this.exists = false;
this.cursor = null;
if (!soft)
{
this.parent.removeChild(this);
this.game = null;
this.exists = false;
}
}
/**

View file

@ -284,7 +284,7 @@ Phaser.StateManager.prototype = {
{
this.game.tweens.removeAll();
this.game.world.destroy();
this.game.world.shutdown();
this.game.physics.clear();

View file

@ -94,15 +94,16 @@ Phaser.World.prototype.setBounds = function (x, y, width, height) {
/**
* Destroyer of worlds.
* @method Phaser.World#destroy
* @method Phaser.World#shutdown
*/
Phaser.World.prototype.destroy = function () {
Phaser.World.prototype.shutdown = function () {
this.camera.reset();
this.game.input.reset(true);
this.removeAll();
// World is a Group, so run a soft destruction on this and all children.
this.destroy(true, true);
}

View file

@ -29,6 +29,10 @@ Phaser.Text = function (game, x, y, text, style) {
{
text = ' ';
}
else
{
text = text.toString();
}
/**
* @property {Phaser.Game} game - A reference to the currently running Game.

View file

@ -40,6 +40,12 @@ Phaser.InputHandler = function (sprite) {
*/
this.useHandCursor = false;
/**
* @property {boolean} _setHandCursor - Did this Sprite trigger the hand cursor?
* @private
*/
this._setHandCursor = false;
/**
* @property {boolean} isDragged - true if the Sprite is being currently dragged.
* @default
@ -302,6 +308,12 @@ Phaser.InputHandler.prototype = {
if (this.enabled)
{
if (this._setHandCursor)
{
this.game.canvas.style.cursor = "default";
this._setHandCursor = false;
}
this.enabled = false;
this.game.input.interactiveItems.remove(this);
@ -314,6 +326,37 @@ Phaser.InputHandler.prototype = {
},
/**
* Checks if the object this InputHandler is bound to is valid for consideration in the Pointer move event.
* This is called by Phaser.Pointer and shouldn't typically be called directly.
*
* @method Phaser.InputHandler#validForInput
* @protected
* @param {number} highestID - The highest ID currently processed by the Pointer.
* @param {number} highestRenderID - The highest Render Order ID currently processed by the Pointer.
* @return {boolean} True if the object this InputHandler is bound to should be considered as valid for input detection.
*/
validForInput: function (highestID, highestRenderID) {
if (this.sprite.scale.x === 0 || this.sprite.scale.y === 0)
{
return false;
}
if (this.pixelPerfectClick || this.pixelPerfectOver)
{
return true;
}
if (this.priorityID > highestID || (this.priorityID === highestID && this.sprite._cache[3] < highestRenderID))
{
return true;
}
return false;
},
/**
* The x coordinate of the Input pointer, relative to the top-left of the parent Sprite.
* This value is only set when the pointer is over this Sprite.
@ -679,6 +722,7 @@ Phaser.InputHandler.prototype = {
if (this.useHandCursor && this._pointerData[pointer.id].isDragged === false)
{
this.game.canvas.style.cursor = "pointer";
this._setHandCursor = false;
}
this.sprite.events.onInputOver.dispatch(this.sprite, pointer);
@ -707,6 +751,7 @@ Phaser.InputHandler.prototype = {
if (this.useHandCursor && this._pointerData[pointer.id].isDragged === false)
{
this.game.canvas.style.cursor = "default";
this._setHandCursor = false;
}
if (this.sprite && this.sprite.events)
@ -796,6 +841,7 @@ Phaser.InputHandler.prototype = {
if (this.useHandCursor)
{
this.game.canvas.style.cursor = "default";
this._setHandCursor = false;
}
}

View file

@ -367,7 +367,7 @@ Phaser.Pointer.prototype = {
do
{
// If the object is using pixelPerfect checks, or has a higher InputManager.PriorityID OR if the priority ID is the same as the current highest AND it has a higher renderOrderID, then set it to the top
if (currentNode.pixelPerfectClick || currentNode.pixelPerfectOver || currentNode.priorityID > this._highestInputPriorityID || (currentNode.priorityID === this._highestInputPriorityID && currentNode.sprite._cache[3] < this._highestRenderOrderID))
if (currentNode.validForInput(this._highestInputPriorityID, this._highestRenderOrderID))
{
if ((!fromClick && currentNode.checkPointerOver(this)) || (fromClick && currentNode.checkPointerDown(this)))
{