Merge pull request #1059 from lucbloom/spritesheet-to-framecount

Sprite Sheet => frame count
This commit is contained in:
Richard Davey 2014-08-28 01:49:15 +01:00
commit 7fe4abc5c4
3 changed files with 34 additions and 65 deletions

View file

@ -112,15 +112,7 @@ Phaser.AnimationManager.prototype = {
this.isLoaded = true;
if (this._frameData)
{
return true;
}
else
{
return false;
}
return true;
},
/**
@ -137,12 +129,6 @@ Phaser.AnimationManager.prototype = {
*/
add: function (name, frames, frameRate, loop, useNumericIndex) {
if (this._frameData === null)
{
console.warn('No FrameData available for Phaser.Animation ' + name);
return;
}
frames = frames || [];
frameRate = frameRate || 60;
@ -442,14 +428,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, 'frameTotal', {
get: function () {
if (this._frameData)
{
return this._frameData.total;
}
else
{
return -1;
}
return this._frameData.total;
}
});
@ -491,7 +470,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, 'frame', {
set: function (value) {
if (typeof value === 'number' && this._frameData && this._frameData.getFrame(value) !== null)
if (typeof value === 'number' && this._frameData.getFrame(value) !== null)
{
this.currentFrame = this._frameData.getFrame(value);
@ -530,7 +509,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, 'frameName', {
set: function (value) {
if (typeof value === 'string' && this._frameData && this._frameData.getFrameByName(value) !== null)
if (typeof value === 'string' && this._frameData.getFrameByName(value) !== null)
{
this.currentFrame = this._frameData.getFrameByName(value);

View file

@ -251,32 +251,21 @@ Phaser.Image.prototype.loadTexture = function (key, frame) {
return;
}
if (this.game.cache.isSpriteSheet(key))
this.key = key;
var frameData = this.game.cache.getFrameData(key);
if (typeof frame === 'string')
{
this.key = key;
var frameData = this.game.cache.getFrameData(key);
if (typeof frame === 'string')
{
this._frame = 0;
this._frameName = frame;
this.setTexture(PIXI.TextureCache[frameData.getFrameByName(frame).uuid]);
return;
}
else
{
this._frame = frame;
this._frameName = '';
this.setTexture(PIXI.TextureCache[frameData.getFrame(frame).uuid]);
return;
}
this._frame = 0;
this._frameName = frame;
this.setTexture(PIXI.TextureCache[frameData.getFrameByName(frame).uuid]);
}
else
{
this.key = key;
this.setTexture(PIXI.TextureCache[key]);
return;
this._frame = frame;
this._frameName = '';
this.setTexture(PIXI.TextureCache[frameData.getFrame(frame).uuid]);
}
}
@ -613,7 +602,7 @@ Object.defineProperty(Phaser.Image.prototype, "frame", {
set: function(value) {
if (value !== this.frame && this.game.cache.isSpriteSheet(this.key))
if (value !== this.frame)
{
var frameData = this.game.cache.getFrameData(this.key);
@ -642,7 +631,7 @@ Object.defineProperty(Phaser.Image.prototype, "frameName", {
set: function(value) {
if (value !== this.frameName && this.game.cache.isSpriteSheet(this.key))
if (value !== this.frameName)
{
var frameData = this.game.cache.getFrameData(this.key);

View file

@ -253,7 +253,7 @@ Phaser.Cache.prototype = {
*/
addSpriteSheet: function (key, url, data, frameWidth, frameHeight, frameMax, margin, spacing) {
this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight, margin: margin, spacing: spacing };
this._images[key] = { url: url, data: data, frameWidth: frameWidth, frameHeight: frameHeight, margin: margin, spacing: spacing };
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
@ -289,7 +289,7 @@ Phaser.Cache.prototype = {
*/
addTextureAtlas: function (key, url, data, atlasData, format) {
this._images[key] = { url: url, data: data, spriteSheet: true };
this._images[key] = { url: url, data: data };
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
@ -322,7 +322,7 @@ Phaser.Cache.prototype = {
*/
addBitmapFont: function (key, url, data, xmlData, xSpacing, ySpacing) {
this._images[key] = { url: url, data: data, spriteSheet: true };
this._images[key] = { url: url, data: data };
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
@ -422,9 +422,11 @@ Phaser.Cache.prototype = {
*/
addImage: function (key, url, data) {
this._images[key] = { url: url, data: data, spriteSheet: false };
this._images[key] = { url: url, data: data };
this._images[key].frame = new Phaser.Frame(0, 0, 0, data.width, data.height, key, this.game.rnd.uuid());
this._images[key].frameData = new Phaser.FrameData();
this._images[key].frameData.addFrame(new Phaser.Frame(0, 0, 0, data.width, data.height, url, this.game.rnd.uuid()));
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
@ -859,7 +861,7 @@ Phaser.Cache.prototype = {
*/
getFrameData: function (key) {
if (this._images[key] && this._images[key].frameData)
if (this._images[key])
{
return this._images[key].frameData;
}
@ -878,7 +880,6 @@ Phaser.Cache.prototype = {
if (this._images[key])
{
this._images[key].spriteSheet = true;
this._images[key].frameData = frameData;
}
@ -893,7 +894,7 @@ Phaser.Cache.prototype = {
*/
getFrameByIndex: function (key, frame) {
if (this._images[key] && this._images[key].frameData)
if (this._images[key])
{
return this._images[key].frameData.getFrame(frame);
}
@ -910,7 +911,7 @@ Phaser.Cache.prototype = {
*/
getFrameByName: function (key, frame) {
if (this._images[key] && this._images[key].frameData)
if (this._images[key])
{
return this._images[key].frameData.getFrameByName(frame);
}
@ -927,7 +928,7 @@ Phaser.Cache.prototype = {
*/
getFrame: function (key) {
if (this._images[key] && this._images[key].spriteSheet === false)
if (this._images[key])
{
return this._images[key].frame;
}
@ -1042,20 +1043,20 @@ Phaser.Cache.prototype = {
},
/**
* Check whether an image asset is sprite sheet or not.
* Get the number of frames in this image.
*
* @method Phaser.Cache#isSpriteSheet
* @param {string} key - Asset key of the sprite sheet you want.
* @return {boolean} True if the image is a sprite sheet.
* @method Phaser.Cache#getFrameCount
* @param {string} key - Asset key of the image you want.
* @return {integer} Then number of frames. 0 if the image is not found.
*/
isSpriteSheet: function (key) {
getFrameCount: function (key) {
if (this._images[key])
{
return this._images[key].spriteSheet;
return this._images[key].frameData.total;
}
return false;
return 0;
},