More Pixi updates.

This commit is contained in:
photonstorm 2015-03-05 19:26:53 +00:00
parent f4eff6359c
commit fe9a9fcd63
2 changed files with 32 additions and 29 deletions

View file

@ -494,7 +494,7 @@ PIXI.DisplayObjectContainer.prototype._renderCanvas = function(renderSession)
renderSession.maskManager.pushMask(this._mask, renderSession);
}
for (i = 0; i < this.children.length; i++)
for (var i = 0; i < this.children.length; i++)
{
this.children[i]._renderCanvas(renderSession);
}

View file

@ -87,10 +87,6 @@ PIXI.Sprite = function(texture)
{
this.onTextureUpdate();
}
// else
// {
// this.texture.on( 'update', this.onTextureUpdate.bind(this) );
// }
this.renderable = true;
@ -107,13 +103,16 @@ PIXI.Sprite.prototype.constructor = PIXI.Sprite;
* @type Number
*/
Object.defineProperty(PIXI.Sprite.prototype, 'width', {
get: function() {
return this.scale.x * this.texture.frame.width;
},
set: function(value) {
this.scale.x = value / this.texture.frame.width;
this._width = value;
}
});
/**
@ -123,13 +122,16 @@ Object.defineProperty(PIXI.Sprite.prototype, 'width', {
* @type Number
*/
Object.defineProperty(PIXI.Sprite.prototype, 'height', {
get: function() {
return this.scale.y * this.texture.frame.height;
},
set: function(value) {
this.scale.y = value / this.texture.frame.height;
this._height = value;
}
});
/**
@ -156,8 +158,6 @@ PIXI.Sprite.prototype.onTextureUpdate = function()
// so if _width is 0 then width was not set..
if (this._width) this.scale.x = this._width / this.texture.frame.width;
if (this._height) this.scale.y = this._height / this.texture.frame.height;
//this.updateFrame = true;
};
/**
@ -220,8 +220,6 @@ PIXI.Sprite.prototype.getBounds = function(matrix)
var x4 = a * w1 + c * h0 + tx;
var y4 = d * h0 + b * w1 + ty;
minX = x1 < minX ? x1 : minX;
minX = x2 < minX ? x2 : minX;
minX = x3 < minX ? x3 : minX;
@ -294,7 +292,7 @@ PIXI.Sprite.prototype._renderWebGL = function(renderSession)
spriteBatch.render(this);
// now loop through the children and make sure they get rendered
for(i=0,j=this.children.length; i<j; i++)
for (i = 0; i < this.children.length; i++)
{
this.children[i]._renderWebGL(renderSession);
}
@ -312,7 +310,7 @@ PIXI.Sprite.prototype._renderWebGL = function(renderSession)
renderSession.spriteBatch.render(this);
// simple render children!
for(i=0,j=this.children.length; i<j; i++)
for (i = 0; i < this.children.length; i++)
{
this.children[i]._renderWebGL(renderSession);
}
@ -356,9 +354,11 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
renderSession.scaleMode = this.texture.baseTexture.scaleMode;
renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.LINEAR);
}
// If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions
var dx = (this.texture.trim) ? this.texture.trim.x - this.anchor.x * this.texture.trim.width : this.anchor.x * -this.texture.frame.width;
var dy = (this.texture.trim) ? this.texture.trim.y - this.anchor.y * this.texture.trim.height : this.anchor.y * -this.texture.frame.height;
// Allow for pixel rounding
if (renderSession.roundPixels)
{
@ -418,7 +418,7 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
}
// OVERWRITE
for (var i = 0, j = this.children.length; i < j; i++)
for (var i = 0; i < this.children.length; i++)
{
this.children[i]._renderCanvas(renderSession);
}
@ -444,7 +444,9 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
PIXI.Sprite.fromFrame = function(frameId)
{
var texture = PIXI.TextureCache[frameId];
if (!texture) throw new Error('The frameId "' + frameId + '" does not exist in the texture cache' + this);
return new PIXI.Sprite(texture);
};
@ -461,5 +463,6 @@ PIXI.Sprite.fromFrame = function(frameId)
PIXI.Sprite.fromImage = function(imageId, crossorigin, scaleMode)
{
var texture = PIXI.Texture.fromImage(imageId, crossorigin, scaleMode);
return new PIXI.Sprite(texture);
};