Skip to content

Commit ddc85cf

Browse files
committed
Added support for tint and alpha to RenderTexture
1 parent 0538134 commit ddc85cf

4 files changed

Lines changed: 42 additions & 3 deletions

File tree

src/gameobjects/rendertexture/RenderTexture.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ var RenderTexture = new Class({
7878
this.initMatrixStack();
7979

8080
this.renderer = scene.sys.game.renderer;
81+
this.globalTint = 0xFFFFFFF;
82+
this.globalAlpha = 1.0;
8183

8284
if (this.renderer.type === CONST.WEBGL)
8385
{
@@ -120,7 +122,39 @@ var RenderTexture = new Class({
120122
this.renderer.deleteTexture(this.texture);
121123
this.renderer.deleteFramebuffer(this.framebuffer);
122124
}
123-
}
125+
},
126+
127+
/**
128+
* [description]
129+
*
130+
* @method Phaser.GameObjects.RenderTexture#setGlobalTint
131+
* @since 3.2.0
132+
*
133+
* @param {int} tint [description]
134+
*
135+
* @return {Phaser.GameObjects.RenderTexture} [description]
136+
*/
137+
setGlobalTint: function (tint)
138+
{
139+
this.globalTint = tint;
140+
return this;
141+
},
142+
143+
/**
144+
* [description]
145+
*
146+
* @method Phaser.GameObjects.RenderTexture#setGlobalAlpha
147+
* @since 3.2.0
148+
*
149+
* @param {float} alpha [description]
150+
*
151+
* @return {Phaser.GameObjects.RenderTexture} [description]
152+
*/
153+
setGlobalAlpha: function (alpha)
154+
{
155+
this.globalAlpha = alpha;
156+
return this;
157+
},
124158

125159
/**
126160
* Fills the Render Texture with the given color.

src/gameobjects/rendertexture/RenderTextureCanvas.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ var RenderTextureCanvas = {
2020
draw: function (texture, frame, x, y)
2121
{
2222
var matrix = this.currentMatrix;
23+
24+
this.context.globalAlpha = this.globalAlpha;
2325
this.context.setTransform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
2426
this.context.drawImage(texture.source[frame.sourceIndex].image, frame.x, frame.y, frame.width, frame.height, x, y, frame.width, frame.height);
27+
2528
return this;
2629
}
2730

src/gameobjects/rendertexture/RenderTextureWebGL.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ var RenderTextureWebGL = {
2727
draw: function (texture, frame, x, y)
2828
{
2929
var glTexture = texture.source[frame.sourceIndex].glTexture;
30+
var tint = (this.globalTint >> 16) + (this.globalTint & 0xff00) + ((this.globalTint & 0xff) << 16);
3031
this.renderer.setFramebuffer(this.framebuffer);
31-
this.renderer.pipelines.TextureTintPipeline.drawTexture(glTexture, x, y, frame.x, frame.y, frame.width, frame.height, this.currentMatrix);
32+
this.renderer.pipelines.TextureTintPipeline.drawTexture(glTexture, x, y, tint, this.globalAlpha, frame.x, frame.y, frame.width, frame.height, this.currentMatrix);
3233
this.renderer.setFramebuffer(null);
3334
return this;
3435
}

src/renderer/webgl/pipelines/TextureTintPipeline.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,7 @@ var TextureTintPipeline = new Class({
16891689
drawTexture: function (
16901690
texture,
16911691
srcX, srcY,
1692+
tint, alpha,
16921693
frameX, frameY, frameWidth, frameHeight,
16931694
transformMatrix
16941695
)
@@ -1730,7 +1731,7 @@ var TextureTintPipeline = new Class({
17301731
var v0 = (frameY / textureHeight);
17311732
var u1 = (frameX + frameWidth) / textureWidth;
17321733
var v1 = (frameY + frameHeight) / textureHeight;
1733-
var tint = 0xffffffff;
1734+
var tint = Utils.getTintAppendFloatAlpha(tint, alpha);
17341735

17351736
this.setTexture2D(texture, 0);
17361737

0 commit comments

Comments
 (0)