mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 23:20:59 +00:00
Cache.getRenderTexture will retrieve a RenderTexture that is stored in the Phaser Cache. This method replaces Cache.getTexture which is now deprecated.
Cache.autoResolveURL is a new boolean (default `false`) that automatically builds a cached map of all loaded assets vs. their absolute URLs, for use with Cache.getURL and Cache.checkURL. Note that in 2.1.3 and earlier this was enabled by default, but has since been moved behind this property which needs to be set to `true` *before* you load any assets to enable. Cache._resolveUrl has been renamed to Cache._resolveURL internally and gained a new parameter. This method is a private internal one. Cache.getUrl is deprecated. The same method is now available as Cache.getURL. XML files weren't being added to the URL map. Cache._resolveURL was causing a Sound double-load in Firefox and causing errors (thanks @domonyiv #1253)
This commit is contained in:
parent
12c2f83bfc
commit
0f3cda0aed
2 changed files with 103 additions and 29 deletions
|
@ -75,13 +75,21 @@ Version 2.1.4 - "Bethal" - in development
|
|||
|
||||
### New Features
|
||||
|
||||
* Cache.getRenderTexture will retrieve a RenderTexture that is stored in the Phaser Cache. This method replaces Cache.getTexture which is now deprecated.
|
||||
* Cache.autoResolveURL is a new boolean (default `false`) that automatically builds a cached map of all loaded assets vs. their absolute URLs, for use with Cache.getURL and Cache.checkURL. Note that in 2.1.3 and earlier this was enabled by default, but has since been moved behind this property which needs to be set to `true` *before* you load any assets to enable.
|
||||
|
||||
|
||||
### Updates
|
||||
|
||||
* TypeScript definitions fixes and updates (thanks @clark-stevenson)
|
||||
* Cache._resolveUrl has been renamed to Cache._resolveURL internally and gained a new parameter. This method is a private internal one.
|
||||
* Cache.getUrl is deprecated. The same method is now available as Cache.getURL.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Tilemaps in WebGL wouldn't update after the first frame due to a subtle change in how Pixi uploads new textures to the GPU.
|
||||
* XML files weren't being added to the URL map.
|
||||
* Cache._resolveURL was causing a Sound double-load in Firefox and causing errors (thanks @domonyiv #1253)
|
||||
|
||||
|
||||
For details about changes made in previous versions of Phaser see the full Change Log at https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md
|
||||
|
|
|
@ -19,6 +19,11 @@ Phaser.Cache = function (game) {
|
|||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {boolean} autoResolveURL - Automatically resolve resource URLs to absolute paths for use with the Cache.getURL method.
|
||||
*/
|
||||
this.autoResolveURL = false;
|
||||
|
||||
/**
|
||||
* @property {object} _canvases - Canvas key-value container.
|
||||
* @private
|
||||
|
@ -294,7 +299,7 @@ Phaser.Cache.prototype = {
|
|||
|
||||
this._images[key].frameData = Phaser.AnimationParser.spriteSheet(this.game, key, frameWidth, frameHeight, frameMax, margin, spacing);
|
||||
|
||||
this._urlMap[this._resolveUrl(url)] = this._images[key];
|
||||
this._resolveURL(url, this._images[key]);
|
||||
|
||||
},
|
||||
|
||||
|
@ -311,7 +316,7 @@ Phaser.Cache.prototype = {
|
|||
|
||||
this._tilemaps[key] = { url: url, data: mapData, format: format };
|
||||
|
||||
this._urlMap[this._resolveUrl(url)] = this._tilemaps[key];
|
||||
this._resolveURL(url, this._tilemaps[key]);
|
||||
|
||||
},
|
||||
|
||||
|
@ -345,7 +350,7 @@ Phaser.Cache.prototype = {
|
|||
this._images[key].frameData = Phaser.AnimationParser.XMLData(this.game, atlasData, key);
|
||||
}
|
||||
|
||||
this._urlMap[this._resolveUrl(url)] = this._images[key];
|
||||
this._resolveURL(url, this._images[key]);
|
||||
|
||||
},
|
||||
|
||||
|
@ -371,7 +376,7 @@ Phaser.Cache.prototype = {
|
|||
|
||||
this._bitmapFont[key] = PIXI.BitmapText.fonts[key];
|
||||
|
||||
this._urlMap[this._resolveUrl(url)] = this._bitmapFont[key];
|
||||
this._resolveURL(url, this._bitmapFont[key]);
|
||||
|
||||
},
|
||||
|
||||
|
@ -388,7 +393,7 @@ Phaser.Cache.prototype = {
|
|||
|
||||
this._physics[key] = { url: url, data: JSONData, format: format };
|
||||
|
||||
this._urlMap[this._resolveUrl(url)] = this._physics[key];
|
||||
this._resolveURL(url, this._physics[key]);
|
||||
|
||||
},
|
||||
|
||||
|
@ -446,7 +451,7 @@ Phaser.Cache.prototype = {
|
|||
|
||||
this._text[key] = { url: url, data: data };
|
||||
|
||||
this._urlMap[this._resolveUrl(url)] = this._text[key];
|
||||
this._resolveURL(url, this._text[key]);
|
||||
|
||||
},
|
||||
|
||||
|
@ -462,7 +467,7 @@ Phaser.Cache.prototype = {
|
|||
|
||||
this._json[key] = { url: url, data: data };
|
||||
|
||||
this._urlMap[this._resolveUrl(url)] = this._json[key];
|
||||
this._resolveURL(url, this._json[key]);
|
||||
|
||||
},
|
||||
|
||||
|
@ -478,10 +483,12 @@ Phaser.Cache.prototype = {
|
|||
|
||||
this._xml[key] = { url: url, data: data };
|
||||
|
||||
this._resolveURL(url, this._xml[key]);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds an Image file into the Cache. The file must have already been loaded, typically via Phaser.Loader.
|
||||
* Adds an Image file into the Cache. The file must have already been loaded, typically via Phaser.Loader, but can also have been loaded into the DOM.
|
||||
*
|
||||
* @method Phaser.Cache#addImage
|
||||
* @param {string} key - The unique key by which you will reference this object.
|
||||
|
@ -499,7 +506,7 @@ Phaser.Cache.prototype = {
|
|||
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
||||
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
|
||||
|
||||
this._urlMap[this._resolveUrl(url)] = this._images[key];
|
||||
this._resolveURL(url, this._images[key]);
|
||||
|
||||
},
|
||||
|
||||
|
@ -527,7 +534,7 @@ Phaser.Cache.prototype = {
|
|||
|
||||
this._sounds[key] = { url: url, data: data, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag, locked: this.game.sound.touchLocked };
|
||||
|
||||
this._urlMap[this._resolveUrl(url)] = this._sounds[key];
|
||||
this._resolveURL(url, this._sounds[key]);
|
||||
|
||||
},
|
||||
|
||||
|
@ -701,7 +708,6 @@ Phaser.Cache.prototype = {
|
|||
{
|
||||
return fixture;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// We did not find the requested fixture
|
||||
|
@ -899,14 +905,17 @@ Phaser.Cache.prototype = {
|
|||
|
||||
/**
|
||||
* Checks if the given URL has been loaded into the Cache.
|
||||
* This method will only work if Cache.autoResolveURL was set to `true` before any preloading took place.
|
||||
* The method will make a DOM src call to the URL given, so please be aware of this for certain file types, such as Sound files on Firefox
|
||||
* which may cause double-load instances.
|
||||
*
|
||||
* @method Phaser.Cache#checkUrl
|
||||
* @method Phaser.Cache#checkURL
|
||||
* @param {string} url - The url to check for in the cache.
|
||||
* @return {boolean} True if the url exists, otherwise false.
|
||||
*/
|
||||
checkUrl: function (url) {
|
||||
checkURL: function (url) {
|
||||
|
||||
if (this._urlMap[this._resolveUrl(url)])
|
||||
if (this._urlMap[this._resolveURL(url)])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -916,11 +925,11 @@ Phaser.Cache.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Get image data by key.
|
||||
* Gets an image by its key. Note that this returns a DOM Image object, not a Phaser object.
|
||||
*
|
||||
* @method Phaser.Cache#getImage
|
||||
* @param {string} key - Asset key of the image to retrieve from the Cache.
|
||||
* @return {object} The image data if found in the Cache, otherwise `null`.
|
||||
* @return {Image} The Image object if found in the Cache, otherwise `null`.
|
||||
*/
|
||||
getImage: function (key) {
|
||||
|
||||
|
@ -1063,7 +1072,30 @@ Phaser.Cache.prototype = {
|
|||
/**
|
||||
* Get a RenderTexture by key.
|
||||
*
|
||||
* @method Phaser.Cache#getRenderTexture
|
||||
* @param {string} key - Asset key of the RenderTexture to retrieve from the Cache.
|
||||
* @return {Phaser.RenderTexture} The RenderTexture object.
|
||||
*/
|
||||
getRenderTexture: function (key) {
|
||||
|
||||
if (this._textures[key])
|
||||
{
|
||||
return this._textures[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('Phaser.Cache.getTexture: Invalid key: "' + key + '"');
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* DEPRECATED: Please use Cache.getRenderTexture instead. This method will be removed in Phaser 2.2.0.
|
||||
*
|
||||
* Get a RenderTexture by key.
|
||||
*
|
||||
* @method Phaser.Cache#getTexture
|
||||
* @deprecated Please use Cache.getRenderTexture instead. This method will be removed in Phaser 2.2.0.
|
||||
* @param {string} key - Asset key of the RenderTexture to retrieve from the Cache.
|
||||
* @return {Phaser.RenderTexture} The RenderTexture object.
|
||||
*/
|
||||
|
@ -1249,21 +1281,42 @@ Phaser.Cache.prototype = {
|
|||
|
||||
/**
|
||||
* Get a cached object by the URL.
|
||||
* This only returns a value if you set Cache.autoResolveURL to `true` *before* starting the preload of any assets.
|
||||
* Be aware that every call to this function makes a DOM src query, so use carefully and double-check for implications in your target browsers/devices.
|
||||
*
|
||||
* @method Phaser.Cache#getURL
|
||||
* @param {string} url - The url for the object loaded to get from the cache.
|
||||
* @return {object} The cached object.
|
||||
*/
|
||||
getURL: function (url) {
|
||||
|
||||
var url = this._resolveURL(url);
|
||||
|
||||
if (url)
|
||||
{
|
||||
return this._urlMap[url];
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('Phaser.Cache.getUrl: Invalid url: "' + url + '" or Cache.autoResolveURL was false');
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* DEPRECATED: Please use Cache.getURL instead.
|
||||
* Get a cached object by the URL.
|
||||
* This only returns a value if you set Cache.autoResolveURL to `true` *before* starting the preload of any assets.
|
||||
* Be aware that every call to this function makes a DOM src query, so use carefully and double-check for implications in your target browsers/devices.
|
||||
*
|
||||
* @method Phaser.Cache#getUrl
|
||||
* @deprecated Please use Cache.getURL instead.
|
||||
* @param {string} url - The url for the object loaded to get from the cache.
|
||||
* @return {object} The cached object.
|
||||
*/
|
||||
getUrl: function (url) {
|
||||
|
||||
if (this._urlMap[this._resolveUrl(url)])
|
||||
{
|
||||
return this._urlMap[this._resolveUrl(url)];
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('Phaser.Cache.getUrl: Invalid url: "' + url + '"');
|
||||
}
|
||||
return this.getURL(url);
|
||||
|
||||
},
|
||||
|
||||
|
@ -1469,14 +1522,21 @@ Phaser.Cache.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Resolves a URL to its absolute form.
|
||||
* Resolves a URL to its absolute form and stores it in Cache._urlMap as long as Cache.autoResolveURL is set to `true`.
|
||||
* This is then looked-up by the Cache.getURL and Cache.checkURL calls.
|
||||
*
|
||||
* @method Phaser.Cache#_resolveUrl
|
||||
* @param {string} url - The URL to resolve.
|
||||
* @return {string} The resolved URL.
|
||||
* @method Phaser.Cache#_resolveURL
|
||||
* @private
|
||||
* @param {string} url - The URL to resolve. This is appended to Loader.baseURL.
|
||||
* @param {object} [data] - The data associated with the URL to be stored to the URL Map.
|
||||
* @return {string} The resolved URL.
|
||||
*/
|
||||
_resolveUrl: function (url) {
|
||||
_resolveURL: function (url, data) {
|
||||
|
||||
if (!this.autoResolveURL)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
this._urlResolver.src = this.game.load.baseURL + url;
|
||||
|
||||
|
@ -1485,6 +1545,12 @@ Phaser.Cache.prototype = {
|
|||
// Ensure no request is actually made
|
||||
this._urlResolver.src = '';
|
||||
|
||||
// Record the URL to the map
|
||||
if (data)
|
||||
{
|
||||
this._urlMap[this._urlTemp] = data;
|
||||
}
|
||||
|
||||
return this._urlTemp;
|
||||
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue