diff --git a/src/gameobjects/components/Depth.js b/src/gameobjects/components/Depth.js index d4e198792..a7700dde5 100644 --- a/src/gameobjects/components/Depth.js +++ b/src/gameobjects/components/Depth.js @@ -12,6 +12,8 @@ * @since 3.0.0 */ +var ArrayUtils = require('../../utils/array'); + var Depth = { /** @@ -83,6 +85,128 @@ var Depth = { this.depth = value; + return this; + }, + + /** + * Bring this Game Object to top of display list. + * + * @method Phaser.GameObjects.Components.Depth#bringMeToTop + * @since 3.80.2 + * @return {this} This Game Object instance. + */ + bringMeToTop: function() + { + var list; + if (this.parentContainer) + { + list = this.parentContainer.list; + } + else if (this.displayList) + { + list = this.displayList.list; + } + + if (!list) + { + return this; + } + + ArrayUtils.BringToTop(list, this); + + return this; + }, + + /** + * Send this Game Object to bottom of display list. + * + * @method Phaser.GameObjects.Components.Depth#sendMeToBack + * @since 3.80.2 + * @return {this} This Game Object instance. + */ + sendMeToBack: function() + { + var list; + if (this.parentContainer) + { + list = this.parentContainer.list; + } + else if (this.displayList) + { + list = this.displayList.list; + } + + if (!list) + { + return this; + } + + ArrayUtils.SendToBack(list, this); + + return this; + }, + + /** + * Move this Game Object below another Game Object. + * + * @method Phaser.GameObjects.Components.Depth#moveMyDepthBelow + * @since 3.80.2 + * + * @param {Phaser.GameObjects.GameObject} gameObject - Move this Game Object below this Game Object. + * + * @return {this} This Game Object instance. + */ + moveMyDepthBelow: function(gameObject) + { + var list; + if (this.parentContainer) + { + list = this.parentContainer.list; + } + else if (this.displayList) + { + list = this.displayList.list; + } + + if (!list) + { + return this; + } + + ArrayUtils.MoveBelow(list, this, gameObject); + + return this; + }, + + /** + * Move this Game Object above another Game Object. + * + * @method Phaser.GameObjects.Components.Depth#moveMyDepthAbove + * @since 3.80.2 + * + * @param {Phaser.GameObjects.GameObject} gameObject - Move this Game Object above this Game Object. + * + * @return {this} This Game Object instance. + */ + moveMyDepthAbove: function(gameObject) + { + var list; + if (this.parentContainer) + { + list = this.parentContainer.list; + } + else if (this.displayList) + { + list = this.displayList.list; + } + + if (!list) + { + return this; + } + + ArrayUtils.MoveAbove(list, this, gameObject); + return this; } diff --git a/src/loader/LoaderPlugin.js b/src/loader/LoaderPlugin.js index 2d71275d8..3acda0e40 100644 --- a/src/loader/LoaderPlugin.js +++ b/src/loader/LoaderPlugin.js @@ -12,6 +12,7 @@ var Events = require('./events'); var FileTypesManager = require('./FileTypesManager'); var GetFastValue = require('../utils/object/GetFastValue'); var GetValue = require('../utils/object/GetValue'); +var IsPlainObject = require('../utils/object/IsPlainObject'); var PluginCache = require('../plugins/PluginCache'); var SceneEvents = require('../scene/events'); var XHRSettings = require('./XHRSettings'); @@ -678,6 +679,180 @@ var LoaderPlugin = new Class({ return (total > 0); }, + /** + * Remove the resources listed in an Asset Pack. + * + * This removes Animations from the Animation Manager, Textures from the Texture Manager, and all other assets from their respective caches. + * It doesn't remove the Pack itself from the JSON cache, if it exists there. + * If the Pack includes another Pack, its resources will be removed too. + * + * @method Phaser.Loader.LoaderPlugin#removePack + * @since 3.90.0 + * + * @param {(string|object)} packKey - The key of an Asset Pack in the JSON cache, or a Pack File data. + * @param {string} [dataKey] - A key in the Pack data, if you want to process only a section of it. + */ + removePack: function (packKey, dataKey) + { + var animationManager = this.systems.anims; + var cacheManager = this.cacheManager; + var textureManager = this.textureManager; + + var cacheMap = { + animation: 'json', + aseprite: 'json', + audio: 'audio', + audioSprite: 'audio', + binary: 'binary', + bitmapFont: 'bitmapFont', + css: null, + glsl: 'shader', + html: 'html', + json: 'json', + obj: 'obj', + plugin: null, + scenePlugin: null, + script: null, + spine: 'json', + text: 'text', + tilemapCSV: 'tilemap', + tilemapImpact: 'tilemap', + tilemapTiledJSON: 'tilemap', + video: 'video', + xml: 'xml' + }; + + var pack; + + if (IsPlainObject(packKey)) + { + pack = packKey; + } + else + { + pack = cacheManager.json.get(packKey); + + if (!pack) + { + console.warn('Asset Pack not found in JSON cache:', packKey); + + return; + } + } + + if (dataKey) + { + pack = { _: pack[dataKey] }; + } + + for (var configKey in pack) + { + var config = pack[configKey]; + var prefix = GetFastValue(config, 'prefix', ''); + var files = GetFastValue(config, 'files'); + var defaultType = GetFastValue(config, 'defaultType'); + + if (Array.isArray(files)) + { + for (var i = 0; i < files.length; i++) + { + var file = files[i]; + var type = (file.hasOwnProperty('type')) ? file.type : defaultType; + + if (!type) + { + console.warn('No type:', file); + + continue; + } + + var fileKey = prefix + file.key; + + if (type === 'animation') + { + animationManager.remove(fileKey); + } + + if (type === 'aseprite' || type === 'atlas' || type === 'atlasXML' || type === 'htmlTexture' || type === 'image' || type === 'multiatlas' || type === 'spritesheet' || type === 'svg' || type === 'texture' || type === 'unityAtlas') + { + textureManager.remove(fileKey); + + if (!cacheMap[type]) + { + continue; + } + } + + if (type === 'pack') + { + this.removePack(fileKey, file.dataKey); + + continue; + } + + if (type === 'spine') + { + var spineAtlas = cacheManager.custom.spine.get(fileKey); + + if (!spineAtlas) + { + continue; + } + + var spinePrefix = (spineAtlas.prefix === undefined) ? '' : spineAtlas.prefix; + + cacheManager.custom.spine.remove(fileKey); + + var spineTexture = cacheManager.custom.spineTextures.get(fileKey); + + if (!spineTexture) + { + continue; + } + + cacheManager.custom.spineTextures.remove(fileKey); + + for (var j = 0; j < spineTexture.pages.length; j++) + { + var page = spineTexture.pages[j]; + var textureKey = spinePrefix + page.name; + var altTextureKey = fileKey + ':' + textureKey; + + if (textureManager.exists(altTextureKey)) + { + textureManager.remove(altTextureKey); + } + else + { + textureManager.remove(textureKey); + } + } + } + + var cacheName = cacheMap[type]; + + if (cacheName === null) + { + // Nothing to remove. + + continue; + } + + if (!cacheName) + { + console.warn('Unknown type:', type); + + continue; + } + + var cache = cacheManager[cacheName]; + + cache.remove(fileKey); + } + } + } + }, + /** * Is the Loader actively loading, or processing loaded files? * diff --git a/src/time/Timeline.js b/src/time/Timeline.js index 18dbcc3ee..e61be0dc9 100644 --- a/src/time/Timeline.js +++ b/src/time/Timeline.js @@ -133,6 +133,22 @@ var Timeline = new Class({ */ this.elapsed = 0; + /** + * The Timeline's delta time scale. + * + * Values higher than 1 increase the speed of time, while values smaller than 1 decrease it. + * A value of 0 freezes time and is effectively equivalent to pausing the Timeline. + * + * This doesn't affect the delta time scale of any Tweens created by the Timeline. + * You will have to set the `timeScale` of each Tween or the Tween Manager if you want them to match. + * + * @name Phaser.Time.Timeline#timeScale + * @type {number} + * @default + * @since 3.90.0 + */ + this.timeScale = 1; + /** * Whether the Timeline is running (`true`) or active (`false`). * @@ -241,7 +257,7 @@ var Timeline = new Class({ return; } - this.elapsed += delta; + this.elapsed += delta * this.timeScale; }, /** @@ -689,7 +705,7 @@ var Timeline = new Class({ { var events = this.events; - for (i = 0; i < events.length; i++) + for (var i = 0; i < events.length; i++) { var event = events[i]; diff --git a/src/tweens/tween/TweenChain.js b/src/tweens/tween/TweenChain.js index 22c7e14d1..6db53ddf6 100644 --- a/src/tweens/tween/TweenChain.js +++ b/src/tweens/tween/TweenChain.js @@ -376,8 +376,7 @@ var TweenChain = new Class({ data[i].reset(false); } - this.currentIndex = 0; - this.currentTween = data[0]; + this.setCurrentTween(0); }, /**