diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index 098dda4..e482e21 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -62,10 +62,10 @@ TransformStatic.prototype.updateSkew = function () { - this._cy = Math.cos(this.skew.y); - this._sy = Math.sin(this.skew.y); - this._nsx = Math.sin(this.skew.x); - this._cx = Math.cos(this.skew.x); + this._cy = Math.cos(this.skew._y); + this._sy = Math.sin(this.skew._y); + this._nsx = Math.sin(this.skew._x); + this._cx = Math.cos(this.skew._x); this._localID ++; }; @@ -80,10 +80,10 @@ // get the matrix values of the displayobject based on its transform properties.. var a,b,c,d; - a = this._cr * this.scale.x; - b = this._sr * this.scale.x; - c = -this._sr * this.scale.y; - d = this._cr * this.scale.y; + a = this._cr * this.scale._x; + b = this._sr * this.scale._x; + c = -this._sr * this.scale._y; + d = this._cr * this.scale._y; lt.a = this._cy * a + this._sy * c; lt.b = this._cy * b + this._sy * d; @@ -115,10 +115,10 @@ // get the matrix values of the displayobject based on its transform properties.. var a,b,c,d; - a = this._cr * this.scale.x; - b = this._sr * this.scale.x; - c = -this._sr * this.scale.y; - d = this._cr * this.scale.y; + a = this._cr * this.scale._x; + b = this._sr * this.scale._x; + c = -this._sr * this.scale._y; + d = this._cr * this.scale._y; lt.a = this._cy * a + this._sy * c; lt.b = this._cy * b + this._sy * d; diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index 098dda4..e482e21 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -62,10 +62,10 @@ TransformStatic.prototype.updateSkew = function () { - this._cy = Math.cos(this.skew.y); - this._sy = Math.sin(this.skew.y); - this._nsx = Math.sin(this.skew.x); - this._cx = Math.cos(this.skew.x); + this._cy = Math.cos(this.skew._y); + this._sy = Math.sin(this.skew._y); + this._nsx = Math.sin(this.skew._x); + this._cx = Math.cos(this.skew._x); this._localID ++; }; @@ -80,10 +80,10 @@ // get the matrix values of the displayobject based on its transform properties.. var a,b,c,d; - a = this._cr * this.scale.x; - b = this._sr * this.scale.x; - c = -this._sr * this.scale.y; - d = this._cr * this.scale.y; + a = this._cr * this.scale._x; + b = this._sr * this.scale._x; + c = -this._sr * this.scale._y; + d = this._cr * this.scale._y; lt.a = this._cy * a + this._sy * c; lt.b = this._cy * b + this._sy * d; @@ -115,10 +115,10 @@ // get the matrix values of the displayobject based on its transform properties.. var a,b,c,d; - a = this._cr * this.scale.x; - b = this._sr * this.scale.x; - c = -this._sr * this.scale.y; - d = this._cr * this.scale.y; + a = this._cr * this.scale._x; + b = this._sr * this.scale._x; + c = -this._sr * this.scale._y; + d = this._cr * this.scale._y; lt.a = this._cy * a + this._sy * c; lt.b = this._cy * b + this._sy * d; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index b4cd276..fe30bb2 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -63,6 +63,8 @@ * @member {number} * @default 0xFFFFFF */ + this._tint = null; + this._tintRGB = null; this.tint = 0xFFFFFF; /** @@ -92,7 +94,19 @@ // call texture setter this.texture = texture || Texture.EMPTY; - this.vertexData = new Float32Array(16); + + /** + * this is used to store the vertex data of the sprite (basically a quad) + * @type {Float32Array} + */ + this.vertexData = new Float32Array(8); + + /** + * this is used to calculate the bounds of the object IF it is a trimmed sprite + * @type {Float32Array} + */ + this.vertexTrimmedData = null; + this._transformID = -1; this._textureID = -1; } @@ -141,6 +155,18 @@ } }, + tint: { + get: function () + { + return this._tint; + }, + set: function (value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } + }, + /** * The texture that the sprite is using * @@ -232,20 +258,20 @@ if (trim) { // if the sprite is trimmed and is not a tilingsprite then we need to add the extra space before transforming the sprite coords.. - w1 = trim.x - this.anchor.x * orig.width; + w1 = trim.x - this.anchor._x * orig.width; w0 = w1 + trim.width; - h1 = trim.y - this.anchor.y * orig.height; + h1 = trim.y - this.anchor._y * orig.height; h0 = h1 + trim.height; } else { - w0 = (orig.width ) * (1-this.anchor.x); - w1 = (orig.width ) * -this.anchor.x; + w0 = orig.width * (1-this.anchor._x); + w1 = orig.width * -this.anchor._x; - h0 = orig.height * (1-this.anchor.y); - h1 = orig.height * -this.anchor.y; + h0 = orig.height * (1-this.anchor._y); + h1 = orig.height * -this.anchor._y; } // xy @@ -266,53 +292,47 @@ }; /** - * we need this method to be compatible with pixiv3. v3 does calculate bounds of original texture are, not trimmed one + * calculates worldTransform * vertices for a non texture with a trim. store it in vertexTrimmedData + * This is used to ensure that the true width and height of a trimmed texture is respected */ -Sprite.prototype.calculateBoundsVertices = function () +Sprite.prototype.calculateTrimmedVertices = function () { - var texture = this._texture, - trim = texture.trim, - vertexData = this.vertexData, - orig = texture.orig; - - if (!trim || trim.width === orig.width && trim.height === orig.height) { - vertexData[8] = vertexData[0]; - vertexData[9] = vertexData[1]; - vertexData[10] = vertexData[2]; - vertexData[11] = vertexData[3]; - vertexData[12] = vertexData[4]; - vertexData[13] = vertexData[5]; - vertexData[14] = vertexData[6]; - vertexData[15] = vertexData[7]; - return; + if(!this.vertexTrimmedData) + { + this.vertexTrimmedData = new Float32Array(8); } + // lets do some special trim code! + var texture = this._texture, + vertexData = this.vertexTrimmedData, + orig = texture.orig; + + // lets calculate the new untrimmed bounds.. var wt = this.transform.worldTransform, a = wt.a, b = wt.b, c = wt.c, d = wt.d, tx = wt.tx, ty = wt.ty, w0, w1, h0, h1; + w0 = (orig.width ) * (1-this.anchor._x); + w1 = (orig.width ) * -this.anchor._x; - w0 = (orig.width ) * (1-this.anchor.x); - w1 = (orig.width ) * -this.anchor.x; - - h0 = orig.height * (1-this.anchor.y); - h1 = orig.height * -this.anchor.y; + h0 = orig.height * (1-this.anchor._y); + h1 = orig.height * -this.anchor._y; // xy - vertexData[8] = a * w1 + c * h1 + tx; - vertexData[9] = d * h1 + b * w1 + ty; + vertexData[0] = a * w1 + c * h1 + tx; + vertexData[1] = d * h1 + b * w1 + ty; // xy - vertexData[10] = a * w0 + c * h1 + tx; - vertexData[11] = d * h1 + b * w0 + ty; + vertexData[2] = a * w0 + c * h1 + tx; + vertexData[3] = d * h1 + b * w0 + ty; // xy - vertexData[12] = a * w0 + c * h0 + tx; - vertexData[13] = d * h0 + b * w0 + ty; + vertexData[4] = a * w0 + c * h0 + tx; + vertexData[5] = d * h0 + b * w0 + ty; // xy - vertexData[14] = a * w1 + c * h0 + tx; - vertexData[15] = d * h0 + b * w1 + ty; + vertexData[6] = a * w1 + c * h0 + tx; + vertexData[7] = d * h0 + b * w1 + ty; }; /** @@ -341,11 +361,26 @@ renderer.plugins.sprite.render(this); }; + Sprite.prototype._calculateBounds = function () { - this.calculateVertices(); - // if we have already done this on THIS frame. - this._bounds.addQuad(this.vertexData); + + var trim = this._texture.trim, + orig = this._texture.orig; + + //First lets check to see if the current texture has a trim.. + if (!trim || trim.width === orig.width && trim.height === orig.height) { + + // no trim! lets use the usual calculations.. + this.calculateVertices(); + this._bounds.addQuad(this.vertexData); + } + else + { + // lets calculate a special trimmed bounds... + this.calculateTrimmedVertices(); + this._bounds.addQuad(this.vertexTrimmedData); + } }; /** @@ -359,8 +394,8 @@ if(this.children.length === 0) { - this._bounds.minX = -this._texture.orig.width * this.anchor.x; - this._bounds.minY = -this._texture.orig.height * this.anchor.y; + this._bounds.minX = -this._texture.orig.width * this.anchor._x; + this._bounds.minY = -this._texture.orig.height * this.anchor._y; this._bounds.maxX = this._texture.orig.width; this._bounds.maxY = this._texture.orig.height; diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index 098dda4..e482e21 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -62,10 +62,10 @@ TransformStatic.prototype.updateSkew = function () { - this._cy = Math.cos(this.skew.y); - this._sy = Math.sin(this.skew.y); - this._nsx = Math.sin(this.skew.x); - this._cx = Math.cos(this.skew.x); + this._cy = Math.cos(this.skew._y); + this._sy = Math.sin(this.skew._y); + this._nsx = Math.sin(this.skew._x); + this._cx = Math.cos(this.skew._x); this._localID ++; }; @@ -80,10 +80,10 @@ // get the matrix values of the displayobject based on its transform properties.. var a,b,c,d; - a = this._cr * this.scale.x; - b = this._sr * this.scale.x; - c = -this._sr * this.scale.y; - d = this._cr * this.scale.y; + a = this._cr * this.scale._x; + b = this._sr * this.scale._x; + c = -this._sr * this.scale._y; + d = this._cr * this.scale._y; lt.a = this._cy * a + this._sy * c; lt.b = this._cy * b + this._sy * d; @@ -115,10 +115,10 @@ // get the matrix values of the displayobject based on its transform properties.. var a,b,c,d; - a = this._cr * this.scale.x; - b = this._sr * this.scale.x; - c = -this._sr * this.scale.y; - d = this._cr * this.scale.y; + a = this._cr * this.scale._x; + b = this._sr * this.scale._x; + c = -this._sr * this.scale._y; + d = this._cr * this.scale._y; lt.a = this._cy * a + this._sy * c; lt.b = this._cy * b + this._sy * d; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index b4cd276..fe30bb2 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -63,6 +63,8 @@ * @member {number} * @default 0xFFFFFF */ + this._tint = null; + this._tintRGB = null; this.tint = 0xFFFFFF; /** @@ -92,7 +94,19 @@ // call texture setter this.texture = texture || Texture.EMPTY; - this.vertexData = new Float32Array(16); + + /** + * this is used to store the vertex data of the sprite (basically a quad) + * @type {Float32Array} + */ + this.vertexData = new Float32Array(8); + + /** + * this is used to calculate the bounds of the object IF it is a trimmed sprite + * @type {Float32Array} + */ + this.vertexTrimmedData = null; + this._transformID = -1; this._textureID = -1; } @@ -141,6 +155,18 @@ } }, + tint: { + get: function () + { + return this._tint; + }, + set: function (value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } + }, + /** * The texture that the sprite is using * @@ -232,20 +258,20 @@ if (trim) { // if the sprite is trimmed and is not a tilingsprite then we need to add the extra space before transforming the sprite coords.. - w1 = trim.x - this.anchor.x * orig.width; + w1 = trim.x - this.anchor._x * orig.width; w0 = w1 + trim.width; - h1 = trim.y - this.anchor.y * orig.height; + h1 = trim.y - this.anchor._y * orig.height; h0 = h1 + trim.height; } else { - w0 = (orig.width ) * (1-this.anchor.x); - w1 = (orig.width ) * -this.anchor.x; + w0 = orig.width * (1-this.anchor._x); + w1 = orig.width * -this.anchor._x; - h0 = orig.height * (1-this.anchor.y); - h1 = orig.height * -this.anchor.y; + h0 = orig.height * (1-this.anchor._y); + h1 = orig.height * -this.anchor._y; } // xy @@ -266,53 +292,47 @@ }; /** - * we need this method to be compatible with pixiv3. v3 does calculate bounds of original texture are, not trimmed one + * calculates worldTransform * vertices for a non texture with a trim. store it in vertexTrimmedData + * This is used to ensure that the true width and height of a trimmed texture is respected */ -Sprite.prototype.calculateBoundsVertices = function () +Sprite.prototype.calculateTrimmedVertices = function () { - var texture = this._texture, - trim = texture.trim, - vertexData = this.vertexData, - orig = texture.orig; - - if (!trim || trim.width === orig.width && trim.height === orig.height) { - vertexData[8] = vertexData[0]; - vertexData[9] = vertexData[1]; - vertexData[10] = vertexData[2]; - vertexData[11] = vertexData[3]; - vertexData[12] = vertexData[4]; - vertexData[13] = vertexData[5]; - vertexData[14] = vertexData[6]; - vertexData[15] = vertexData[7]; - return; + if(!this.vertexTrimmedData) + { + this.vertexTrimmedData = new Float32Array(8); } + // lets do some special trim code! + var texture = this._texture, + vertexData = this.vertexTrimmedData, + orig = texture.orig; + + // lets calculate the new untrimmed bounds.. var wt = this.transform.worldTransform, a = wt.a, b = wt.b, c = wt.c, d = wt.d, tx = wt.tx, ty = wt.ty, w0, w1, h0, h1; + w0 = (orig.width ) * (1-this.anchor._x); + w1 = (orig.width ) * -this.anchor._x; - w0 = (orig.width ) * (1-this.anchor.x); - w1 = (orig.width ) * -this.anchor.x; - - h0 = orig.height * (1-this.anchor.y); - h1 = orig.height * -this.anchor.y; + h0 = orig.height * (1-this.anchor._y); + h1 = orig.height * -this.anchor._y; // xy - vertexData[8] = a * w1 + c * h1 + tx; - vertexData[9] = d * h1 + b * w1 + ty; + vertexData[0] = a * w1 + c * h1 + tx; + vertexData[1] = d * h1 + b * w1 + ty; // xy - vertexData[10] = a * w0 + c * h1 + tx; - vertexData[11] = d * h1 + b * w0 + ty; + vertexData[2] = a * w0 + c * h1 + tx; + vertexData[3] = d * h1 + b * w0 + ty; // xy - vertexData[12] = a * w0 + c * h0 + tx; - vertexData[13] = d * h0 + b * w0 + ty; + vertexData[4] = a * w0 + c * h0 + tx; + vertexData[5] = d * h0 + b * w0 + ty; // xy - vertexData[14] = a * w1 + c * h0 + tx; - vertexData[15] = d * h0 + b * w1 + ty; + vertexData[6] = a * w1 + c * h0 + tx; + vertexData[7] = d * h0 + b * w1 + ty; }; /** @@ -341,11 +361,26 @@ renderer.plugins.sprite.render(this); }; + Sprite.prototype._calculateBounds = function () { - this.calculateVertices(); - // if we have already done this on THIS frame. - this._bounds.addQuad(this.vertexData); + + var trim = this._texture.trim, + orig = this._texture.orig; + + //First lets check to see if the current texture has a trim.. + if (!trim || trim.width === orig.width && trim.height === orig.height) { + + // no trim! lets use the usual calculations.. + this.calculateVertices(); + this._bounds.addQuad(this.vertexData); + } + else + { + // lets calculate a special trimmed bounds... + this.calculateTrimmedVertices(); + this._bounds.addQuad(this.vertexTrimmedData); + } }; /** @@ -359,8 +394,8 @@ if(this.children.length === 0) { - this._bounds.minX = -this._texture.orig.width * this.anchor.x; - this._bounds.minY = -this._texture.orig.height * this.anchor.y; + this._bounds.minX = -this._texture.orig.width * this.anchor._x; + this._bounds.minY = -this._texture.orig.height * this.anchor._y; this._bounds.maxX = this._texture.orig.width; this._bounds.maxY = this._texture.orig.height; diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 0b28a26..0c3e51a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -263,7 +263,7 @@ vertexData = sprite.vertexData; //TODO this sum does not need to be set each frame.. - tint = (sprite.tint >> 16) + (sprite.tint & 0xff00) + ((sprite.tint & 0xff) << 16) + (sprite.worldAlpha * 255 << 24); + tint = sprite._tintRGB + (sprite.worldAlpha * 255 << 24); uvs = sprite._texture._uvs.uvsUint32; textureId = nextTexture._id; diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index 098dda4..e482e21 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -62,10 +62,10 @@ TransformStatic.prototype.updateSkew = function () { - this._cy = Math.cos(this.skew.y); - this._sy = Math.sin(this.skew.y); - this._nsx = Math.sin(this.skew.x); - this._cx = Math.cos(this.skew.x); + this._cy = Math.cos(this.skew._y); + this._sy = Math.sin(this.skew._y); + this._nsx = Math.sin(this.skew._x); + this._cx = Math.cos(this.skew._x); this._localID ++; }; @@ -80,10 +80,10 @@ // get the matrix values of the displayobject based on its transform properties.. var a,b,c,d; - a = this._cr * this.scale.x; - b = this._sr * this.scale.x; - c = -this._sr * this.scale.y; - d = this._cr * this.scale.y; + a = this._cr * this.scale._x; + b = this._sr * this.scale._x; + c = -this._sr * this.scale._y; + d = this._cr * this.scale._y; lt.a = this._cy * a + this._sy * c; lt.b = this._cy * b + this._sy * d; @@ -115,10 +115,10 @@ // get the matrix values of the displayobject based on its transform properties.. var a,b,c,d; - a = this._cr * this.scale.x; - b = this._sr * this.scale.x; - c = -this._sr * this.scale.y; - d = this._cr * this.scale.y; + a = this._cr * this.scale._x; + b = this._sr * this.scale._x; + c = -this._sr * this.scale._y; + d = this._cr * this.scale._y; lt.a = this._cy * a + this._sy * c; lt.b = this._cy * b + this._sy * d; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index b4cd276..fe30bb2 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -63,6 +63,8 @@ * @member {number} * @default 0xFFFFFF */ + this._tint = null; + this._tintRGB = null; this.tint = 0xFFFFFF; /** @@ -92,7 +94,19 @@ // call texture setter this.texture = texture || Texture.EMPTY; - this.vertexData = new Float32Array(16); + + /** + * this is used to store the vertex data of the sprite (basically a quad) + * @type {Float32Array} + */ + this.vertexData = new Float32Array(8); + + /** + * this is used to calculate the bounds of the object IF it is a trimmed sprite + * @type {Float32Array} + */ + this.vertexTrimmedData = null; + this._transformID = -1; this._textureID = -1; } @@ -141,6 +155,18 @@ } }, + tint: { + get: function () + { + return this._tint; + }, + set: function (value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } + }, + /** * The texture that the sprite is using * @@ -232,20 +258,20 @@ if (trim) { // if the sprite is trimmed and is not a tilingsprite then we need to add the extra space before transforming the sprite coords.. - w1 = trim.x - this.anchor.x * orig.width; + w1 = trim.x - this.anchor._x * orig.width; w0 = w1 + trim.width; - h1 = trim.y - this.anchor.y * orig.height; + h1 = trim.y - this.anchor._y * orig.height; h0 = h1 + trim.height; } else { - w0 = (orig.width ) * (1-this.anchor.x); - w1 = (orig.width ) * -this.anchor.x; + w0 = orig.width * (1-this.anchor._x); + w1 = orig.width * -this.anchor._x; - h0 = orig.height * (1-this.anchor.y); - h1 = orig.height * -this.anchor.y; + h0 = orig.height * (1-this.anchor._y); + h1 = orig.height * -this.anchor._y; } // xy @@ -266,53 +292,47 @@ }; /** - * we need this method to be compatible with pixiv3. v3 does calculate bounds of original texture are, not trimmed one + * calculates worldTransform * vertices for a non texture with a trim. store it in vertexTrimmedData + * This is used to ensure that the true width and height of a trimmed texture is respected */ -Sprite.prototype.calculateBoundsVertices = function () +Sprite.prototype.calculateTrimmedVertices = function () { - var texture = this._texture, - trim = texture.trim, - vertexData = this.vertexData, - orig = texture.orig; - - if (!trim || trim.width === orig.width && trim.height === orig.height) { - vertexData[8] = vertexData[0]; - vertexData[9] = vertexData[1]; - vertexData[10] = vertexData[2]; - vertexData[11] = vertexData[3]; - vertexData[12] = vertexData[4]; - vertexData[13] = vertexData[5]; - vertexData[14] = vertexData[6]; - vertexData[15] = vertexData[7]; - return; + if(!this.vertexTrimmedData) + { + this.vertexTrimmedData = new Float32Array(8); } + // lets do some special trim code! + var texture = this._texture, + vertexData = this.vertexTrimmedData, + orig = texture.orig; + + // lets calculate the new untrimmed bounds.. var wt = this.transform.worldTransform, a = wt.a, b = wt.b, c = wt.c, d = wt.d, tx = wt.tx, ty = wt.ty, w0, w1, h0, h1; + w0 = (orig.width ) * (1-this.anchor._x); + w1 = (orig.width ) * -this.anchor._x; - w0 = (orig.width ) * (1-this.anchor.x); - w1 = (orig.width ) * -this.anchor.x; - - h0 = orig.height * (1-this.anchor.y); - h1 = orig.height * -this.anchor.y; + h0 = orig.height * (1-this.anchor._y); + h1 = orig.height * -this.anchor._y; // xy - vertexData[8] = a * w1 + c * h1 + tx; - vertexData[9] = d * h1 + b * w1 + ty; + vertexData[0] = a * w1 + c * h1 + tx; + vertexData[1] = d * h1 + b * w1 + ty; // xy - vertexData[10] = a * w0 + c * h1 + tx; - vertexData[11] = d * h1 + b * w0 + ty; + vertexData[2] = a * w0 + c * h1 + tx; + vertexData[3] = d * h1 + b * w0 + ty; // xy - vertexData[12] = a * w0 + c * h0 + tx; - vertexData[13] = d * h0 + b * w0 + ty; + vertexData[4] = a * w0 + c * h0 + tx; + vertexData[5] = d * h0 + b * w0 + ty; // xy - vertexData[14] = a * w1 + c * h0 + tx; - vertexData[15] = d * h0 + b * w1 + ty; + vertexData[6] = a * w1 + c * h0 + tx; + vertexData[7] = d * h0 + b * w1 + ty; }; /** @@ -341,11 +361,26 @@ renderer.plugins.sprite.render(this); }; + Sprite.prototype._calculateBounds = function () { - this.calculateVertices(); - // if we have already done this on THIS frame. - this._bounds.addQuad(this.vertexData); + + var trim = this._texture.trim, + orig = this._texture.orig; + + //First lets check to see if the current texture has a trim.. + if (!trim || trim.width === orig.width && trim.height === orig.height) { + + // no trim! lets use the usual calculations.. + this.calculateVertices(); + this._bounds.addQuad(this.vertexData); + } + else + { + // lets calculate a special trimmed bounds... + this.calculateTrimmedVertices(); + this._bounds.addQuad(this.vertexTrimmedData); + } }; /** @@ -359,8 +394,8 @@ if(this.children.length === 0) { - this._bounds.minX = -this._texture.orig.width * this.anchor.x; - this._bounds.minY = -this._texture.orig.height * this.anchor.y; + this._bounds.minX = -this._texture.orig.width * this.anchor._x; + this._bounds.minY = -this._texture.orig.height * this.anchor._y; this._bounds.maxX = this._texture.orig.width; this._bounds.maxY = this._texture.orig.height; diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 0b28a26..0c3e51a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -263,7 +263,7 @@ vertexData = sprite.vertexData; //TODO this sum does not need to be set each frame.. - tint = (sprite.tint >> 16) + (sprite.tint & 0xff00) + ((sprite.tint & 0xff) << 16) + (sprite.worldAlpha * 255 << 24); + tint = sprite._tintRGB + (sprite.worldAlpha * 255 << 24); uvs = sprite._texture._uvs.uvsUint32; textureId = nextTexture._id; diff --git a/test/core/Bounds.js b/test/core/Bounds.js index 328bca9..71f9d86 100644 --- a/test/core/Bounds.js +++ b/test/core/Bounds.js @@ -360,4 +360,31 @@ expect(bounds.width).to.equal(20); expect(bounds.height).to.equal(20); }); + + it('should ensure bounds respect the trim of a texture ', function() { + + var parent = new PIXI.Container(); + var baseTexture = new PIXI.BaseRenderTexture(100, 100); + + var orig = new PIXI.Rectangle(0,0,100,50); + var frame = new PIXI.Rectangle(2,2,50,50); + var trim = new PIXI.Rectangle(25,0,50,50); + + var trimmedTexture = new PIXI.Texture(baseTexture, frame, orig, trim); + + var sprite = new PIXI.Sprite(trimmedTexture); + + sprite.position.x = 20; + sprite.position.y = 20; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(100); + expect(bounds.height).to.equal(50); + + }); }); \ No newline at end of file