Skip to content

Commit 3c7293a

Browse files
committed
Updated AnimationParser and fixed LoadTexture calls.
1 parent bab50d7 commit 3c7293a

4 files changed

Lines changed: 13 additions & 28 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ For the full list of p2 additions please read [their change log](https://github.
392392
* Added Phaser.Keyboard.COMMA and Phaser.Keyboard.PERIOD to the consts list.
393393
* Canvas.setSmoothingEnabled only applies the value of the property exists, which avoids the Chrome webkit prefix deprecation warnings.
394394
* PIXI._CompileShader can now take an array or a string for the fragment src.
395+
* AnimationParser.spriteSheet can now accept either a string-based key or an HTML Image object as the key argument.
395396

396397
### Bug Fixes
397398

src/animation/AnimationParser.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,24 @@ Phaser.AnimationParser = {
1717
*
1818
* @method Phaser.AnimationParser.spriteSheet
1919
* @param {Phaser.Game} game - A reference to the currently running game.
20-
* @param {string} key - The Game.Cache asset key of the Sprite Sheet image.
20+
* @param {string|Image} key - The Game.Cache asset key of the Sprite Sheet image or an actual HTML Image element.
2121
* @param {number} frameWidth - The fixed width of each frame of the animation.
2222
* @param {number} frameHeight - The fixed height of each frame of the animation.
23-
* @param {number} [frameMax=-1] - The total number of animation frames to extact from the Sprite Sheet. The default value of -1 means "extract all frames".
23+
* @param {number} [frameMax=-1] - The total number of animation frames to extract from the Sprite Sheet. The default value of -1 means "extract all frames".
2424
* @param {number} [margin=0] - If the frames have been drawn with a margin, specify the amount here.
2525
* @param {number} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here.
2626
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
2727
*/
2828
spriteSheet: function (game, key, frameWidth, frameHeight, frameMax, margin, spacing) {
2929

30-
// How big is our image?
31-
var img = game.cache.getImage(key);
30+
var img = key;
3231

33-
if (img == null)
32+
if (typeof key === 'string')
33+
{
34+
img = game.cache.getImage(key);
35+
}
36+
37+
if (img === null)
3438
{
3539
return null;
3640
}

src/gameobjects/components/LoadTexture.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,8 @@ Phaser.Component.LoadTexture.prototype = {
9292

9393
this.key = img.key;
9494
this.setTexture(new PIXI.Texture(img.base));
95-
96-
setFrame = !this.animations.loadFrameData(cache.getFrameData(this.key), frame);
97-
98-
// if (key === null || key === undefined)
99-
// {
100-
// this.key = '__default';
101-
// // this.setTexture(PIXI.TextureCache[this.key]);
102-
// this.setTexture(cache.getTexture(this.key));
103-
// }
104-
// else if (typeof key === 'string' && !cache.checkImageKey(key))
105-
// {
106-
// console.warn("Texture with key '" + key + "' not found.");
107-
// this.key = '__missing';
108-
// // this.setTexture(PIXI.TextureCache[this.key]);
109-
// this.setTexture(cache.getTexture(this.key));
110-
// }
111-
// else
112-
// {
113-
// this.setTexture(new PIXI.Texture(PIXI.BaseTextureCache[key]));
114-
115-
// setFrame = !this.animations.loadFrameData(cache.getFrameData(key), frame);
116-
// }
95+
96+
setFrame = !this.animations.loadFrameData(img.frameData, frame);
11797
}
11898

11999
if (setFrame)

src/loader/Cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ Phaser.Cache.prototype = {
566566
margin: margin,
567567
spacing: spacing,
568568
base: new PIXI.BaseTexture(data),
569-
frameData: Phaser.AnimationParser.spriteSheet(this.game, key, frameWidth, frameHeight, frameMax, margin, spacing)
569+
frameData: Phaser.AnimationParser.spriteSheet(this.game, data, frameWidth, frameHeight, frameMax, margin, spacing)
570570
};
571571

572572
this._cache.image[key] = obj;

0 commit comments

Comments
 (0)