diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b08e6572..0c1aa03de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,10 @@ The process of managing scissors in the WebGLRenderer has been completely rewrit * The `load.html` method has been renamed to `load.htmlTexture`. * The method `batchVertices` in the TextureTintPipeline has been renamed to `batchQuad` which more accurately describes what it does. * In ArcadePhysics `Body.setSize` you can now choose to not pass width and height values to the method. If you do this it will check to see if the parent Game Object has a texture frame, and if so, it will use the frame sizes for the Body dimensions (thanks @tarsupin) +* `PluginCache.destroyCorePlugins` will remove all core plugins from the cache. Be very careful calling this as Phaser cannot restart or create any new Scenes once this has been called. +* `PluginCache.destroyCustomPlugins` will remove all custom plugins from the cache. +* `PluginManager.destroy` will now clear all custom plugins from the Plugin Cache. This fixes an issue with not being able to destroy a Phaser game instance and restart it if it used a custom plugin. +* `Game.destroy` has a new boolean argument `noReturn`. If set it will remove all Core plugins when the game instance is destroyed. You cannot restart Phaser on the same web page after doing this, so only set it if you know you're done and don't need to run Phaser again. ### Game Config Resolution Specific Bug Fixes diff --git a/src/boot/Game.js b/src/boot/Game.js index ee159933f..96a63920d 100644 --- a/src/boot/Game.js +++ b/src/boot/Game.js @@ -19,6 +19,7 @@ var DOMContentLoaded = require('../dom/DOMContentLoaded'); var EventEmitter = require('eventemitter3'); var FacebookInstantGamesPlugin = require('../fbinstant/FacebookInstantGamesPlugin'); var InputManager = require('../input/InputManager'); +var PluginCache = require('../plugins/PluginCache'); var PluginManager = require('../plugins/PluginManager'); var SceneManager = require('../scene/SceneManager'); var SoundManagerCreator = require('../sound/SoundManagerCreator'); @@ -277,6 +278,17 @@ var Game = new Class({ */ this.removeCanvas = false; + /** + * Remove everything when the game is destroyed. + * You cannot create a new Phaser instance on the same web page after doing this. + * + * @name Phaser.Game#noReturn + * @type {boolean} + * @private + * @since 3.12.0 + */ + this.noReturn = false; + /** * Does the window the game is running in currently have focus or not? * This is modified by the VisibilityHandler. @@ -324,6 +336,12 @@ var Game = new Class({ */ boot: function () { + if (!PluginCache.hasCore('EventEmitter')) + { + console.warn('Core Phaser Plugins missing. Cannot start.'); + return; + } + this.isBooted = true; this.config.preBoot(this); @@ -656,17 +674,24 @@ var Game = new Class({ /** * Flags this Game instance as needing to be destroyed on the next frame. * It will wait until the current frame has completed and then call `runDestroy` internally. + * + * If you **do not** need to run Phaser again on the same web page you can set the `noReturn` argument to `true` and it will free-up + * memory being held by the core Phaser plugins. If you do need to create another game instance on the same page, leave this as `false`. * * @method Phaser.Game#destroy * @since 3.0.0 * * @param {boolean} removeCanvas - Set to `true` if you would like the parent canvas element removed from the DOM, or `false` to leave it in place. + * @param {boolean} [noReturn=false] - If `true` all the core Phaser plugins are destroyed. You cannot create another instance of Phaser on the same web page if you do this. */ - destroy: function (removeCanvas) + destroy: function (removeCanvas, noReturn) { + if (noReturn === undefined) { noReturn = false; } + this.pendingDestroy = true; this.removeCanvas = removeCanvas; + this.noReturn = noReturn; }, /** @@ -705,7 +730,7 @@ var Game = new Class({ } this.loop.destroy(); - + this.pendingDestroy = false; }