Added GameObject.ignoreDestroy

This commit is contained in:
Richard Davey 2018-04-13 17:20:46 +01:00
parent 6b2307594a
commit 59bc9dd0d9
2 changed files with 19 additions and 2 deletions

View file

@ -2,6 +2,10 @@
## Version 3.4.1 - Miyako - 13th April 2018
### New Features
* GameObject.ignoreDestroy allows you to control if a Game Object is destroyed or not. Setting the flag will tell it to ignore destroy requests from Groups, Containers and even the Scene itself. See the docs for more details.
### Bug Fixes
* MatterEvents.off() would cause a TypeError if you destroyed the Matter world. Fix #3562 (thanks @pixelscripter)
@ -16,7 +20,7 @@
* Removed the following properties from BaseSound as they are no longer required. Each class that extends BaseSound implements them directly as getters: `mute`, `loop`, `seek` and `volume`.
* The Device.OS test to see if Phaser is running under node.js has been strengthened to support node-like environments like Vue (thanks @Chumper)
* Every Plugin has been updated to correctly follow the same flow through the Scene lifecycle. Instead of listening for the Scene 'boot' event, which is only dispatched once (when the Scene is first created), they will now listen for the Scene 'start' event, which occurs every time the Scene is started. All plugins now consistently follow the same Shutdown and Destroy patterns too, meaning they tidy-up after themselves on a shutdown, not just a destroy. Overall, this change means that there should be less issues when returning to previously closed Scenes, as the plugins will restart themselves properly.
* When shutting down a Scene all Game Objects that belong to the scene will now automatically destroy themselves. They would previously be removed from the display and update lists, but the objects themselves didn't self-destruct.
* When shutting down a Scene all Game Objects that belong to the scene will now automatically destroy themselves. They would previously be removed from the display and update lists, but the objects themselves didn't self-destruct. You can control this on a per-object basis with the `ignoreDestroy` property.
### Examples, Documentation and TypeScript

View file

@ -154,6 +154,19 @@ var GameObject = new Class({
*/
this.body = null;
/**
* This Game Object will ignore all calls made to its destroy method if this flag is set to `true`.
* This includes calls that may come from a Group, Container or the Scene itself.
* While it allows you to persist a Game Object across Scenes, please understand you are entirely
* responsible for managing references to and from this Game Object.
*
* @name Phaser.GameObjects.GameObject#ignoreDestroy
* @type {boolean}
* @default false
* @since 3.4.1
*/
this.ignoreDestroy = false;
// Tell the Scene to re-sort the children
scene.sys.queueDepthSort();
@ -377,7 +390,7 @@ var GameObject = new Class({
destroy: function ()
{
// This Game Object had already been destroyed
if (!this.scene)
if (!this.scene || this.ignoreDestroy)
{
return;
}