Setting Sprite Dimensions before loading complete

Now if you set the width of a Sprite before the sprites texture has
loaded it preserves the specified width and height
This commit is contained in:
Mat Groves 2013-04-14 23:38:28 +01:00
parent 4f503405d3
commit 6ef000059b
9 changed files with 70 additions and 161 deletions

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-04-09 * Compiled: 2013-04-14
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -433,14 +433,14 @@ PIXI.Sprite = function(texture)
* @property width * @property width
* @type #Number * @type #Number
*/ */
this.width = 1; this.width = 0;
/** /**
* The height of the sprite (this is initially set by the texture) * The height of the sprite (this is initially set by the texture)
* @property height * @property height
* @type #Number * @type #Number
*/ */
this.height = 1; this.height = 0;
if(texture.baseTexture.hasLoaded) if(texture.baseTexture.hasLoaded)
{ {
@ -564,8 +564,8 @@ PIXI.Sprite.prototype.setInteractive = function(interactive)
*/ */
PIXI.Sprite.prototype.onTextureUpdate = function(event) PIXI.Sprite.prototype.onTextureUpdate = function(event)
{ {
this.width = this.texture.frame.width; this.width = this.width || this.texture.frame.width;
this.height = this.texture.frame.height; this.height = this.height || this.texture.frame.height;
this.updateFrame = true; this.updateFrame = true;
} }
@ -1798,6 +1798,8 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
{ {
if(this.contextLost)return; if(this.contextLost)return;
// if rendering a new stage clear the batchs.. // if rendering a new stage clear the batchs..
if(this.__stage !== stage) if(this.__stage !== stage)
{ {
@ -3702,23 +3704,8 @@ PIXI.Texture.fromFrame = function(frameId)
*/ */
PIXI.Texture.fromCanvas = function(canvas) PIXI.Texture.fromCanvas = function(canvas)
{ {
// create a canvas id?? var baseTexture = new PIXI.BaseTexture(canvas);
var texture = PIXI.TextureCache[canvas]; return new PIXI.Texture(baseTexture);
if(!texture)
{
var baseTexture = PIXI.BaseTextureCache[canvas];
if(!baseTexture)
{
baseTexture = new PIXI.BaseTexture(canvas);
PIXI.BaseTextureCache[canvas] = baseTexture;
}
texture = new PIXI.Texture(baseTexture);
PIXI.TextureCache[canvas] = texture;
}
return texture;
} }

File diff suppressed because one or more lines are too long

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-04-09 * Compiled: 2013-04-14
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -433,14 +433,14 @@ PIXI.Sprite = function(texture)
* @property width * @property width
* @type #Number * @type #Number
*/ */
this.width = 1; this.width = 0;
/** /**
* The height of the sprite (this is initially set by the texture) * The height of the sprite (this is initially set by the texture)
* @property height * @property height
* @type #Number * @type #Number
*/ */
this.height = 1; this.height = 0;
if(texture.baseTexture.hasLoaded) if(texture.baseTexture.hasLoaded)
{ {
@ -564,8 +564,8 @@ PIXI.Sprite.prototype.setInteractive = function(interactive)
*/ */
PIXI.Sprite.prototype.onTextureUpdate = function(event) PIXI.Sprite.prototype.onTextureUpdate = function(event)
{ {
this.width = this.texture.frame.width; this.width = this.width || this.texture.frame.width;
this.height = this.texture.frame.height; this.height = this.height || this.texture.frame.height;
this.updateFrame = true; this.updateFrame = true;
} }
@ -1798,6 +1798,8 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
{ {
if(this.contextLost)return; if(this.contextLost)return;
// if rendering a new stage clear the batchs.. // if rendering a new stage clear the batchs..
if(this.__stage !== stage) if(this.__stage !== stage)
{ {
@ -3702,23 +3704,8 @@ PIXI.Texture.fromFrame = function(frameId)
*/ */
PIXI.Texture.fromCanvas = function(canvas) PIXI.Texture.fromCanvas = function(canvas)
{ {
// create a canvas id?? var baseTexture = new PIXI.BaseTexture(canvas);
var texture = PIXI.TextureCache[canvas]; return new PIXI.Texture(baseTexture);
if(!texture)
{
var baseTexture = PIXI.BaseTextureCache[canvas];
if(!baseTexture)
{
baseTexture = new PIXI.BaseTexture(canvas);
PIXI.BaseTextureCache[canvas] = baseTexture;
}
texture = new PIXI.Texture(baseTexture);
PIXI.TextureCache[canvas] = texture;
}
return texture;
} }

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-04-09 * Compiled: 2013-04-14
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -433,14 +433,14 @@ PIXI.Sprite = function(texture)
* @property width * @property width
* @type #Number * @type #Number
*/ */
this.width = 1; this.width = 0;
/** /**
* The height of the sprite (this is initially set by the texture) * The height of the sprite (this is initially set by the texture)
* @property height * @property height
* @type #Number * @type #Number
*/ */
this.height = 1; this.height = 0;
if(texture.baseTexture.hasLoaded) if(texture.baseTexture.hasLoaded)
{ {
@ -564,8 +564,8 @@ PIXI.Sprite.prototype.setInteractive = function(interactive)
*/ */
PIXI.Sprite.prototype.onTextureUpdate = function(event) PIXI.Sprite.prototype.onTextureUpdate = function(event)
{ {
this.width = this.texture.frame.width; this.width = this.width || this.texture.frame.width;
this.height = this.texture.frame.height; this.height = this.height || this.texture.frame.height;
this.updateFrame = true; this.updateFrame = true;
} }
@ -1798,6 +1798,8 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
{ {
if(this.contextLost)return; if(this.contextLost)return;
// if rendering a new stage clear the batchs.. // if rendering a new stage clear the batchs..
if(this.__stage !== stage) if(this.__stage !== stage)
{ {
@ -3702,23 +3704,8 @@ PIXI.Texture.fromFrame = function(frameId)
*/ */
PIXI.Texture.fromCanvas = function(canvas) PIXI.Texture.fromCanvas = function(canvas)
{ {
// create a canvas id?? var baseTexture = new PIXI.BaseTexture(canvas);
var texture = PIXI.TextureCache[canvas]; return new PIXI.Texture(baseTexture);
if(!texture)
{
var baseTexture = PIXI.BaseTextureCache[canvas];
if(!baseTexture)
{
baseTexture = new PIXI.BaseTexture(canvas);
PIXI.BaseTextureCache[canvas] = baseTexture;
}
texture = new PIXI.Texture(baseTexture);
PIXI.TextureCache[canvas] = texture;
}
return texture;
} }

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-04-09 * Compiled: 2013-04-14
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -433,14 +433,14 @@ PIXI.Sprite = function(texture)
* @property width * @property width
* @type #Number * @type #Number
*/ */
this.width = 1; this.width = 0;
/** /**
* The height of the sprite (this is initially set by the texture) * The height of the sprite (this is initially set by the texture)
* @property height * @property height
* @type #Number * @type #Number
*/ */
this.height = 1; this.height = 0;
if(texture.baseTexture.hasLoaded) if(texture.baseTexture.hasLoaded)
{ {
@ -564,8 +564,8 @@ PIXI.Sprite.prototype.setInteractive = function(interactive)
*/ */
PIXI.Sprite.prototype.onTextureUpdate = function(event) PIXI.Sprite.prototype.onTextureUpdate = function(event)
{ {
this.width = this.texture.frame.width; this.width = this.width || this.texture.frame.width;
this.height = this.texture.frame.height; this.height = this.height || this.texture.frame.height;
this.updateFrame = true; this.updateFrame = true;
} }
@ -1798,6 +1798,8 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
{ {
if(this.contextLost)return; if(this.contextLost)return;
// if rendering a new stage clear the batchs.. // if rendering a new stage clear the batchs..
if(this.__stage !== stage) if(this.__stage !== stage)
{ {
@ -3702,23 +3704,8 @@ PIXI.Texture.fromFrame = function(frameId)
*/ */
PIXI.Texture.fromCanvas = function(canvas) PIXI.Texture.fromCanvas = function(canvas)
{ {
// create a canvas id?? var baseTexture = new PIXI.BaseTexture(canvas);
var texture = PIXI.TextureCache[canvas]; return new PIXI.Texture(baseTexture);
if(!texture)
{
var baseTexture = PIXI.BaseTextureCache[canvas];
if(!baseTexture)
{
baseTexture = new PIXI.BaseTexture(canvas);
PIXI.BaseTextureCache[canvas] = baseTexture;
}
texture = new PIXI.Texture(baseTexture);
PIXI.TextureCache[canvas] = texture;
}
return texture;
} }

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-04-09 * Compiled: 2013-04-14
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -433,14 +433,14 @@ PIXI.Sprite = function(texture)
* @property width * @property width
* @type #Number * @type #Number
*/ */
this.width = 1; this.width = 0;
/** /**
* The height of the sprite (this is initially set by the texture) * The height of the sprite (this is initially set by the texture)
* @property height * @property height
* @type #Number * @type #Number
*/ */
this.height = 1; this.height = 0;
if(texture.baseTexture.hasLoaded) if(texture.baseTexture.hasLoaded)
{ {
@ -564,8 +564,8 @@ PIXI.Sprite.prototype.setInteractive = function(interactive)
*/ */
PIXI.Sprite.prototype.onTextureUpdate = function(event) PIXI.Sprite.prototype.onTextureUpdate = function(event)
{ {
this.width = this.texture.frame.width; this.width = this.width || this.texture.frame.width;
this.height = this.texture.frame.height; this.height = this.height || this.texture.frame.height;
this.updateFrame = true; this.updateFrame = true;
} }
@ -1798,6 +1798,8 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
{ {
if(this.contextLost)return; if(this.contextLost)return;
// if rendering a new stage clear the batchs.. // if rendering a new stage clear the batchs..
if(this.__stage !== stage) if(this.__stage !== stage)
{ {
@ -3702,23 +3704,8 @@ PIXI.Texture.fromFrame = function(frameId)
*/ */
PIXI.Texture.fromCanvas = function(canvas) PIXI.Texture.fromCanvas = function(canvas)
{ {
// create a canvas id?? var baseTexture = new PIXI.BaseTexture(canvas);
var texture = PIXI.TextureCache[canvas]; return new PIXI.Texture(baseTexture);
if(!texture)
{
var baseTexture = PIXI.BaseTextureCache[canvas];
if(!baseTexture)
{
baseTexture = new PIXI.BaseTexture(canvas);
PIXI.BaseTextureCache[canvas] = baseTexture;
}
texture = new PIXI.Texture(baseTexture);
PIXI.TextureCache[canvas] = texture;
}
return texture;
} }

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-04-09 * Compiled: 2013-04-14
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -433,14 +433,14 @@ PIXI.Sprite = function(texture)
* @property width * @property width
* @type #Number * @type #Number
*/ */
this.width = 1; this.width = 0;
/** /**
* The height of the sprite (this is initially set by the texture) * The height of the sprite (this is initially set by the texture)
* @property height * @property height
* @type #Number * @type #Number
*/ */
this.height = 1; this.height = 0;
if(texture.baseTexture.hasLoaded) if(texture.baseTexture.hasLoaded)
{ {
@ -564,8 +564,8 @@ PIXI.Sprite.prototype.setInteractive = function(interactive)
*/ */
PIXI.Sprite.prototype.onTextureUpdate = function(event) PIXI.Sprite.prototype.onTextureUpdate = function(event)
{ {
this.width = this.texture.frame.width; this.width = this.width || this.texture.frame.width;
this.height = this.texture.frame.height; this.height = this.height || this.texture.frame.height;
this.updateFrame = true; this.updateFrame = true;
} }
@ -1798,6 +1798,8 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
{ {
if(this.contextLost)return; if(this.contextLost)return;
// if rendering a new stage clear the batchs.. // if rendering a new stage clear the batchs..
if(this.__stage !== stage) if(this.__stage !== stage)
{ {
@ -3702,23 +3704,8 @@ PIXI.Texture.fromFrame = function(frameId)
*/ */
PIXI.Texture.fromCanvas = function(canvas) PIXI.Texture.fromCanvas = function(canvas)
{ {
// create a canvas id?? var baseTexture = new PIXI.BaseTexture(canvas);
var texture = PIXI.TextureCache[canvas]; return new PIXI.Texture(baseTexture);
if(!texture)
{
var baseTexture = PIXI.BaseTextureCache[canvas];
if(!baseTexture)
{
baseTexture = new PIXI.BaseTexture(canvas);
PIXI.BaseTextureCache[canvas] = baseTexture;
}
texture = new PIXI.Texture(baseTexture);
PIXI.TextureCache[canvas] = texture;
}
return texture;
} }

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-04-09 * Compiled: 2013-04-14
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -433,14 +433,14 @@ PIXI.Sprite = function(texture)
* @property width * @property width
* @type #Number * @type #Number
*/ */
this.width = 1; this.width = 0;
/** /**
* The height of the sprite (this is initially set by the texture) * The height of the sprite (this is initially set by the texture)
* @property height * @property height
* @type #Number * @type #Number
*/ */
this.height = 1; this.height = 0;
if(texture.baseTexture.hasLoaded) if(texture.baseTexture.hasLoaded)
{ {
@ -564,8 +564,8 @@ PIXI.Sprite.prototype.setInteractive = function(interactive)
*/ */
PIXI.Sprite.prototype.onTextureUpdate = function(event) PIXI.Sprite.prototype.onTextureUpdate = function(event)
{ {
this.width = this.texture.frame.width; this.width = this.width || this.texture.frame.width;
this.height = this.texture.frame.height; this.height = this.height || this.texture.frame.height;
this.updateFrame = true; this.updateFrame = true;
} }
@ -1798,6 +1798,8 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
{ {
if(this.contextLost)return; if(this.contextLost)return;
// if rendering a new stage clear the batchs.. // if rendering a new stage clear the batchs..
if(this.__stage !== stage) if(this.__stage !== stage)
{ {
@ -3702,23 +3704,8 @@ PIXI.Texture.fromFrame = function(frameId)
*/ */
PIXI.Texture.fromCanvas = function(canvas) PIXI.Texture.fromCanvas = function(canvas)
{ {
// create a canvas id?? var baseTexture = new PIXI.BaseTexture(canvas);
var texture = PIXI.TextureCache[canvas]; return new PIXI.Texture(baseTexture);
if(!texture)
{
var baseTexture = PIXI.BaseTextureCache[canvas];
if(!baseTexture)
{
baseTexture = new PIXI.BaseTexture(canvas);
PIXI.BaseTextureCache[canvas] = baseTexture;
}
texture = new PIXI.Texture(baseTexture);
PIXI.TextureCache[canvas] = texture;
}
return texture;
} }

View file

@ -48,14 +48,14 @@ PIXI.Sprite = function(texture)
* @property width * @property width
* @type #Number * @type #Number
*/ */
this.width = 1; this.width = 0;
/** /**
* The height of the sprite (this is initially set by the texture) * The height of the sprite (this is initially set by the texture)
* @property height * @property height
* @type #Number * @type #Number
*/ */
this.height = 1; this.height = 0;
if(texture.baseTexture.hasLoaded) if(texture.baseTexture.hasLoaded)
{ {
@ -179,8 +179,8 @@ PIXI.Sprite.prototype.setInteractive = function(interactive)
*/ */
PIXI.Sprite.prototype.onTextureUpdate = function(event) PIXI.Sprite.prototype.onTextureUpdate = function(event)
{ {
this.width = this.texture.frame.width; this.width = this.width || this.texture.frame.width;
this.height = this.texture.frame.height; this.height = this.height || this.texture.frame.height;
this.updateFrame = true; this.updateFrame = true;
} }