Cache.getPixiTexture will return a PIXI.Texture from the cache based on the given key. A PIXI Texture is created automatically for all images loaded and added to the cache.

Cache.getPixiBaseTexture will return a PIXI.BaseTexture from the cache based on the given key. A PIXI BaseTexture is created automatically for all images loaded and added to the cache.

Cache.getTexture has now been removed (it was deprecated several versions ago). Use Cache.getRenderTexture instead.

Cache.getJSON has a new optional parameter: `parse`. If `true` the method will pass the data through JSON.parse before returning it. The default is `false` to retain backwards compatibility.
This commit is contained in:
photonstorm 2015-04-13 20:25:42 +01:00
parent 615925123a
commit e5f1f6f896
2 changed files with 46 additions and 13 deletions

View file

@ -249,6 +249,8 @@ Version 2.3.1 - "Katar" - in dev
* Tilemap.getTileWorldXY has a new optional parameter: `nonNull` which if set makes it behave in the same way as `getTile` does (thanks @GGAlanSmithee #1722)
* Group.hash is an array (previously available as `Group._hash`, but protected) into which you can add any of its children via `Group.addToHash` and `Group.removeFromHash`. Only children of the Group can be added to and removed from the hash. The hash is used automatically by Arcade Physics in order to perform non z-index based destructive sorting. However if you don't use Arcade Physics, or it isn't a physics enabled Group, then you can use the hash to perform your own sorting and filtering of Group children without touching their z-index (and therefore display draw order).
* Group.physicsSortDirection is a new property allowing you to set a custom sort direction for Arcade Physics Sprites within the Group hash. Previously Arcade Physics used one single sort direction (defined on `Phaser.Physics.Arcade.sortDirection`) but this change allows you to specifically control how each and every Group is sorted, so you can now combine tall and wide Groups with narrow and thin in a single system.
* Cache.getPixiTexture will return a PIXI.Texture from the cache based on the given key. A PIXI Texture is created automatically for all images loaded and added to the cache.
* Cache.getPixiBaseTexture will return a PIXI.BaseTexture from the cache based on the given key. A PIXI BaseTexture is created automatically for all images loaded and added to the cache.
### Updates
@ -263,6 +265,8 @@ Version 2.3.1 - "Katar" - in dev
* Physics.Arcade.sort now calls one of four functions: sortLeftRight, sortRightLeft, sortTopBottom and sortBottomTop. Each of which takes 2 Sprites as arguments.
* Physics.Arcade.sort now doesn't bail out if the Group contains a mixture of physics and non-physics enabled objects, as the Group hash is now only ever populated with physics enabled objects. Also the sort comparison functions no longer return -1 if the bodies are invalid, but zero instead (#1721)
* Group would automatically add a child into the _hash array as soon as the child was created (or moved into the Group). This no longer happens. Instead the child is only added to Group.hash if it is enabled for Arcade Physics. However Group.addToHash and the hash array have been exposed in case you were taking advantage of the _hash even though it was a private array.
* Cache.getTexture has now been removed (it was deprecated several versions ago). Use Cache.getRenderTexture instead.
* Cache.getJSON has a new optional parameter: `parse`. If `true` the method will pass the data through JSON.parse before returning it. The default is `false` to retain backwards compatibility.
### Bug Fixes

View file

@ -1108,24 +1108,43 @@ Phaser.Cache.prototype = {
},
/**
* DEPRECATED: Please use Cache.getRenderTexture instead. This method will be removed in Phaser 2.2.0.
* Gets a PIXI.Texture by key from the Cache.
*
* 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.
* @method Phaser.Cache#getPixiTexture
* @param {string} key - Asset key of the Texture to retrieve from the Cache.
* @return {PIXI.Texture} The Texture object.
*/
getTexture: function (key) {
getPixiTexture: function (key) {
if (this._textures[key])
if (PIXI.TextureCache[key])
{
return this._textures[key];
return PIXI.TextureCache[key];
}
else
{
console.warn('Phaser.Cache.getTexture: Invalid key: "' + key + '"');
console.warn('Phaser.Cache.getPixiTexture: Invalid key: "' + key + '"');
return null;
}
},
/**
* Gets a PIXI.BaseTexture by key from the Cache.
*
* @method Phaser.Cache#getPixiBaseTexture
* @param {string} key - Asset key of the BaseTexture to retrieve from the Cache.
* @return {PIXI.BaseTexture} The BaseTexture object.
*/
getPixiBaseTexture: function (key) {
if (PIXI.BaseTextureCache[key])
{
return PIXI.BaseTextureCache[key];
}
else
{
console.warn('Phaser.Cache.getPixiBaseTexture: Invalid key: "' + key + '"');
return null;
}
},
@ -1245,13 +1264,23 @@ Phaser.Cache.prototype = {
*
* @method Phaser.Cache#getJSON
* @param {string} key - Asset key of the json object to retrieve from the Cache.
* @param {boolean} [parse=false] - If true this will parse the object via JSON.parse before returning it.
* @return {object} The JSON object.
*/
getJSON: function (key) {
getJSON: function (key, parse) {
if (typeof parse === 'undefined') { parse = false; }
if (this._json[key])
{
return this._json[key].data;
if (parse)
{
return JSON.parse(this._json[key].data);
}
else
{
return this._json[key].data;
}
}
else
{