Skip to content

Commit 8e6f957

Browse files
committed
Heavily tweaked tint texture handling. Can now be set by a texture and cached internally.
1 parent a1102d4 commit 8e6f957

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/pixi/display/Sprite.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ PIXI.Sprite = function(texture)
6565
*/
6666
this.tint = 0xFFFFFF;
6767

68+
/**
69+
* The tint applied to the sprite. This is a hex value. A value of 0xFFFFFF will remove any tint effect.
70+
*
71+
* @property cachedTint
72+
* @private
73+
* @type Number
74+
* @default -1
75+
*/
76+
this.cachedTint = -1;
77+
78+
/**
79+
* A canvas that contains the tinted version of the Sprite (in Canvas mode, WebGL doesn't populate this)
80+
*
81+
* @property tintedTexture
82+
* @type Canvas
83+
* @default null
84+
*/
85+
this.tintedTexture = null;
86+
6887
/**
6988
* The blend mode to be applied to the sprite. Set to PIXI.blendModes.NORMAL to remove any blend mode.
7089
*
@@ -143,7 +162,6 @@ Object.defineProperty(PIXI.Sprite.prototype, 'height', {
143162
PIXI.Sprite.prototype.setTexture = function(texture)
144163
{
145164
this.texture = texture;
146-
this.cachedTint = 0xFFFFFF;
147165
this.texture.valid = true;
148166
};
149167

@@ -399,10 +417,11 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession, matrix)
399417

400418
if (this.tint !== 0xFFFFFF)
401419
{
402-
if (this.cachedTint !== this.tint)
420+
if (this.texture.requiresReTint || this.cachedTint !== this.tint)
403421
{
404-
this.cachedTint = this.tint;
405422
this.tintedTexture = PIXI.CanvasTinter.getTintedTexture(this, this.tint);
423+
424+
this.cachedTint = this.tint;
406425
}
407426

408427
renderSession.context.drawImage(this.tintedTexture, 0, 0, cw, ch, dx, dy, cw / resolution, ch / resolution);

0 commit comments

Comments
 (0)