Skip to content

Commit d65c526

Browse files
committed
Cache.addBitmapData has a new parameter: frameData allowing you to pass a Phaser.FrameData object along with the BitmapData.
Cache.getFrameData has a new parameter: `map` which allows you to specify which cache to get the FrameData from, i.e. `Phaser.Cache.IMAGE` or `Phaser.Cache.BITMAPDATA`. Sprite.loadTexture if given a BitmapData as the texture will now query the cache to see if it has any associated FrameData, and if so it will load that into the AnimationManager.
1 parent 26f9e05 commit d65c526

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ Version 2.1.2 - "Whitebridge" - in development
8989
* Text.clearColors resets any previously set colors from `Text.addColor`.
9090
* If you pass a tinted Sprite to `BitmapData.draw` or `BitmapData.copy` it will now draw the tinted version of the Sprite to the BitmapData and not the original texture.
9191
* BitmapData.shadow(color, blur, x, y) provides a quick way to set all the relevant shadow settings, which are then be used in future draw calls.
92+
* Cache.addBitmapData has a new parameter: `frameData` allowing you to pass a `Phaser.FrameData` object along with the BitmapData.
93+
* Cache.getFrameData has a new parameter: `map` which allows you to specify which cache to get the FrameData from, i.e. `Phaser.Cache.IMAGE` or `Phaser.Cache.BITMAPDATA`.
94+
* Sprite.loadTexture if given a BitmapData as the texture will now query the cache to see if it has any associated FrameData, and if so it will load that into the AnimationManager.
9295

9396

9497

src/gameobjects/BitmapData.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ Phaser.BitmapData.prototype = {
10741074
/**
10751075
* Sets the shadow properties of this BitmapDatas context which will affect all draw operations made to it.
10761076
* You can cancel an existing shadow by calling this method and passing no parameters.
1077+
* Note: At the time of writing (October 2014) Chrome still doesn't support shadowBlur used with drawImage.
10771078
*
10781079
* @method Phaser.BitmapData#shadow
10791080
* @param {string} color - The color of the shadow, given in a CSS format, i.e. `#000000` or `rgba(0,0,0,1)`. If `null` or `undefined` the shadow will be reset.

src/gameobjects/Sprite.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ Phaser.Sprite.prototype.loadTexture = function (key, frame, stopAnimation) {
379379
{
380380
// This works from a reference, which probably isn't what we need here
381381
this.setTexture(key.texture);
382+
setFrame = !this.animations.loadFrameData(this.game.cache.getFrameData(key.key, Phaser.Cache.BITMAPDATA), frame);
382383
}
383384
else if (key instanceof PIXI.Texture)
384385
{

src/loader/Cache.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,14 @@ Phaser.Cache.prototype = {
226226
* @method Phaser.Cache#addBitmapData
227227
* @param {string} key - Asset key for this BitmapData.
228228
* @param {Phaser.BitmapData} bitmapData - The BitmapData object to be addded to the cache.
229+
* @param {Phaser.FrameData} [frameData] - Optional FrameData set associated with the given BitmapData.
229230
* @return {Phaser.BitmapData} The BitmapData object to be addded to the cache.
230231
*/
231-
addBitmapData: function (key, bitmapData) {
232+
addBitmapData: function (key, bitmapData, frameData) {
232233

233-
this._bitmapDatas[key] = bitmapData;
234+
bitmapData.key = key;
235+
236+
this._bitmapDatas[key] = { data: bitmapData, frameData: frameData };
234237

235238
return bitmapData;
236239

@@ -591,7 +594,7 @@ Phaser.Cache.prototype = {
591594

592595
if (this._bitmapDatas[key])
593596
{
594-
return this._bitmapDatas[key];
597+
return this._bitmapDatas[key].data;
595598
}
596599
else
597600
{
@@ -904,13 +907,16 @@ Phaser.Cache.prototype = {
904907
*
905908
* @method Phaser.Cache#getFrameData
906909
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
910+
* @param {string} [map=Phaser.Cache.IMAGE] - The asset map to get the frameData from, for example `Phaser.Cache.IMAGE`.
907911
* @return {Phaser.FrameData} The frame data.
908912
*/
909-
getFrameData: function (key) {
913+
getFrameData: function (key, map) {
910914

911-
if (this._images[key])
915+
if (typeof map === 'undefined') { map = Phaser.Cache.IMAGE; }
916+
917+
if (this._cacheMap[map][key])
912918
{
913-
return this._images[key].frameData;
919+
return this._cacheMap[map][key].frameData;
914920
}
915921

916922
return null;

0 commit comments

Comments
 (0)