diff --git a/src/pixi/core/Matrix.js b/src/pixi/core/Matrix.js index df1fd07..cc4ebe2 100644 --- a/src/pixi/core/Matrix.js +++ b/src/pixi/core/Matrix.js @@ -6,7 +6,7 @@ * The Matrix class is now an object, which makes it a lot faster, * here is a representation of it : * | a | b | tx| - * | c | c | ty| + * | c | d | ty| * | 0 | 0 | 1 | * * @class Matrix diff --git a/src/pixi/core/Matrix.js b/src/pixi/core/Matrix.js index df1fd07..cc4ebe2 100644 --- a/src/pixi/core/Matrix.js +++ b/src/pixi/core/Matrix.js @@ -6,7 +6,7 @@ * The Matrix class is now an object, which makes it a lot faster, * here is a representation of it : * | a | b | tx| - * | c | c | ty| + * | c | d | ty| * | 0 | 0 | 1 | * * @class Matrix diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index d147f02..87538d4 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -317,18 +317,13 @@ */ PIXI.Sprite.prototype._renderCanvas = function(renderSession) { - // if the sprite is not visible or the alpha is 0 then no need to render this element - if(this.visible === false || this.alpha === 0)return; + // If the sprite is not visible or the alpha is 0 then no need to render this element + if (this.visible === false || this.alpha === 0) return; - var context = renderSession.context; - var texture = this.texture; - var frame = texture.frame; - var crop = texture.crop; - if (this.blendMode !== renderSession.currentBlendMode) { renderSession.currentBlendMode = this.blendMode; - context.globalCompositeOperation = PIXI.blendModesCanvas[renderSession.currentBlendMode]; + renderSession.context.globalCompositeOperation = PIXI.blendModesCanvas[renderSession.currentBlendMode]; } if (this._mask) @@ -337,101 +332,83 @@ } // Ignore null sources - if (texture.valid) + if (this.texture.valid) { - context.globalAlpha = this.worldAlpha; + renderSession.context.globalAlpha = this.worldAlpha; - var transform = this.worldTransform; - - // Allow for trimming + // Allow for pixel rounding if (renderSession.roundPixels) { - context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx | 0, transform.ty | 0); + renderSession.context.setTransform( + this.worldTransform.a, + this.worldTransform.c, + this.worldTransform.b, + this.worldTransform.d, + this.worldTransform.tx | 0, + this.worldTransform.ty | 0); } else { - context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty); + renderSession.context.setTransform( + this.worldTransform.a, + this.worldTransform.c, + this.worldTransform.b, + this.worldTransform.d, + this.worldTransform.tx, + this.worldTransform.ty); } // If smoothingEnabled is supported and we need to change the smoothing property for this texture if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) { renderSession.scaleMode = this.texture.baseTexture.scaleMode; - context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.LINEAR); + 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; + if (this.tint !== 0xFFFFFF) { if (this.cachedTint !== this.tint) { - // no point tinting an image that has not loaded yet! - if (!texture.baseTexture.hasLoaded) return; - this.cachedTint = this.tint; - //TODO clean up caching - how to clean up the caches? + // TODO clean up caching - how to clean up the caches? this.tintedTexture = PIXI.CanvasTinter.getTintedTexture(this, this.tint); } - if (texture.trim) - { - context.drawImage(this.tintedTexture, - 0, - 0, - crop.width, - crop.height, - texture.trim.x - this.anchor.x * texture.trim.width, - texture.trim.y - this.anchor.y * texture.trim.height, - crop.width, - crop.height); - } - else - { - context.drawImage(this.tintedTexture, - 0, - 0, - frame.width, - frame.height, - (this.anchor.x) * -frame.width, - (this.anchor.y) * -frame.height, - frame.width, - frame.height); - } + renderSession.context.drawImage( + this.tintedTexture, + 0, + 0, + this.texture.crop.width, + this.texture.crop.height, + dx, + dy, + this.texture.crop.width, + this.texture.crop.height); } else { - if (texture.trim) - { - context.drawImage(this.texture.baseTexture.source, - crop.x, - crop.y, - crop.width, - crop.height, - texture.trim.x - this.anchor.x * texture.trim.width, - texture.trim.y - this.anchor.y * texture.trim.height, - crop.width, - crop.height); - } - else - { - context.drawImage(this.texture.baseTexture.source, - crop.x, - crop.y, - crop.width, - crop.height, - this.anchor.x * -frame.width, - this.anchor.y * -frame.height, - crop.width, - crop.height); - } + renderSession.context.drawImage( + this.texture.baseTexture.source, + this.texture.crop.x, + this.texture.crop.y, + this.texture.crop.width, + this.texture.crop.height, + dx, + dy, + this.texture.crop.width, + this.texture.crop.height); } } // OVERWRITE for (var i = 0, j = this.children.length; i < j; i++) { - var child = this.children[i]; - child._renderCanvas(renderSession); + this.children[i]._renderCanvas(renderSession); } if (this._mask)