Skip to content

Commit 91ee135

Browse files
committed
Fixed tint order and exposed via getters.
1 parent 5273799 commit 91ee135

2 files changed

Lines changed: 89 additions & 40 deletions

File tree

src/components/Color.js

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ Phaser.Component.Color = function (gameObject)
2323

2424
this._blendMode = 0;
2525

26-
this._tint = [ 0xffffff, 0xffffff, 0xffffff, 0xffffff ];
26+
this._tint = { topLeft: 0xffffff, topRight: 0xffffff, bottomLeft: 0xffffff, bottomRight: 0xffffff };
27+
this._glTint = { topLeft: 16777215, topRight: 16777215, bottomLeft: 16777215, bottomRight: 16777215 };
2728
this._hasTint = false;
2829

2930
this._r = 0;
@@ -58,9 +59,9 @@ Phaser.Component.Color.prototype = {
5859

5960
clearTint: function ()
6061
{
61-
this._hasTint = false;
62+
this.setTint(0xffffff);
6263

63-
this.setDirty();
64+
this._hasTint = false;
6465
},
6566

6667
setTint: function (topLeft, topRight, bottomLeft, bottomRight)
@@ -72,10 +73,10 @@ Phaser.Component.Color.prototype = {
7273
bottomRight = topLeft;
7374
}
7475

75-
this._tint[0] = topLeft;
76-
this._tint[1] = topRight;
77-
this._tint[2] = bottomLeft;
78-
this._tint[3] = bottomRight;
76+
this.tintTopLeft = topLeft;
77+
this.tintTopRight = topRight;
78+
this.tintBottomLeft = bottomLeft;
79+
this.tintBottomRight = bottomRight;
7980

8081
this._hasTint = true;
8182

@@ -128,34 +129,98 @@ Phaser.Component.Color.prototype = {
128129

129130
Object.defineProperties(Phaser.Component.Color.prototype, {
130131

131-
tint: {
132+
tintTopLeft: {
132133

133134
enumerable: true,
134135

135136
get: function ()
136137
{
137-
return this._tint;
138+
return this._tint.topLeft;
138139
},
139140

140141
set: function (value)
141142
{
142-
if (Array.isArray(value))
143-
{
144-
this._tint = value;
145-
}
146-
else
147-
{
148-
this._tint[0] = value;
149-
this._tint[1] = value;
150-
this._tint[2] = value;
151-
this._tint[3] = value;
152-
}
143+
this._tint.topLeft = value;
144+
// this._glTint.topLeft = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16) + (this._worldAlpha * 255 << 24);
145+
this._glTint.topLeft = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
146+
this.setDirty();
147+
}
148+
149+
},
153150

151+
tintTopRight: {
152+
153+
enumerable: true,
154+
155+
get: function ()
156+
{
157+
return this._tint.topRight;
158+
},
159+
160+
set: function (value)
161+
{
162+
this._tint.topRight = value;
163+
// this._glTint.topRight = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16) + (this._worldAlpha * 255 << 24);
164+
this._glTint.topRight = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
154165
this.setDirty();
155166
}
156167

157168
},
158169

170+
tintBottomLeft: {
171+
172+
enumerable: true,
173+
174+
get: function ()
175+
{
176+
return this._tint.bottomLeft;
177+
},
178+
179+
set: function (value)
180+
{
181+
this._tint.bottomLeft = value;
182+
this._glTint.bottomLeft = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
183+
// this._glTint.bottomLeft = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16) + (this._worldAlpha * 255 << 24);
184+
this.setDirty();
185+
}
186+
187+
},
188+
189+
tintBottomRight: {
190+
191+
enumerable: true,
192+
193+
get: function ()
194+
{
195+
return this._tint.bottomRight;
196+
},
197+
198+
set: function (value)
199+
{
200+
this._tint.bottomRight = value;
201+
this._glTint.bottomRight = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
202+
// this._glTint.bottomRight = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16) + (this._worldAlpha * 255 << 24);
203+
this.setDirty();
204+
}
205+
206+
},
207+
208+
tint: {
209+
210+
enumerable: true,
211+
212+
get: function ()
213+
{
214+
return this._tint;
215+
},
216+
217+
set: function (value)
218+
{
219+
this.setTint(value, value, value, value);
220+
}
221+
222+
},
223+
159224
alpha: {
160225

161226
enumerable: true,

src/renderer/webgl/BatchManager.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -462,54 +462,38 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
462462
ty |= 0;
463463
}
464464

465-
// Interleaved vert and color data
466-
// The color passed here includes an applied tint *see bitwise ops above *
467-
// Better to calculate that in the shader?
468-
469465
var i = this.currentBatchSize * this.vertSize;
470466

471467
// Top Left vert (xy, uv, color)
472468
positions[i++] = a * w1 + c * h1 + tx;
473469
positions[i++] = d * h1 + b * w1 + ty;
474470
positions[i++] = uvs.x0;
475471
positions[i++] = uvs.y0;
476-
477-
var tint = sprite.color.tint[0];
478-
colors[i++] = (tint >> 16) + (tint & 0xff00) + ((tint & 0xff) << 16) + (sprite.color.worldAlpha * 255 << 24);
479-
472+
colors[i++] = sprite.color._glTint.topLeft + (sprite.color.worldAlpha * 255 << 24);
480473
// positions[i++] = textureIndex;
481474

482475
// Top Right vert (xy, uv, color)
483476
positions[i++] = a * w0 + c * h1 + tx;
484477
positions[i++] = d * h1 + b * w0 + ty;
485478
positions[i++] = uvs.x1;
486479
positions[i++] = uvs.y1;
487-
488-
tint = sprite.color.tint[1];
489-
colors[i++] = (tint >> 16) + (tint & 0xff00) + ((tint & 0xff) << 16) + (sprite.color.worldAlpha * 255 << 24);
490-
480+
colors[i++] = sprite.color._glTint.topRight + (sprite.color.worldAlpha * 255 << 24);
491481
// positions[i++] = textureIndex;
492482

493483
// Bottom Right vert (xy, uv, color)
494484
positions[i++] = a * w0 + c * h0 + tx;
495485
positions[i++] = d * h0 + b * w0 + ty;
496486
positions[i++] = uvs.x2;
497487
positions[i++] = uvs.y2;
498-
499-
tint = sprite.color.tint[3];
500-
colors[i++] = (tint >> 16) + (tint & 0xff00) + ((tint & 0xff) << 16) + (sprite.color.worldAlpha * 255 << 24);
501-
488+
colors[i++] = sprite.color._glTint.bottomRight + (sprite.color.worldAlpha * 255 << 24);
502489
// positions[i++] = textureIndex;
503490

504491
// Bottom Left vert (xy, uv, color)
505492
positions[i++] = a * w1 + c * h0 + tx;
506493
positions[i++] = d * h0 + b * w1 + ty;
507494
positions[i++] = uvs.x3;
508495
positions[i++] = uvs.y3;
509-
510-
tint = sprite.color.tint[2];
511-
colors[i++] = (tint >> 16) + (tint & 0xff00) + ((tint & 0xff) << 16) + (sprite.color.worldAlpha * 255 << 24);
512-
496+
colors[i++] = sprite.color._glTint.bottomLeft + (sprite.color.worldAlpha * 255 << 24);
513497
// positions[i++] = textureIndex;
514498

515499
this.sprites[this.currentBatchSize++] = sprite;

0 commit comments

Comments
 (0)