Exposed the alpha corner values and implemented into the Sprite Batch.

This commit is contained in:
Richard Davey 2017-07-25 22:28:02 +01:00
parent aac61e5b57
commit 848ba127ab
3 changed files with 138 additions and 17 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = { var CHECKSUM = {
build: 'ac7c3390-712c-11e7-94b3-cb219d37da47' build: '3e2c85e0-717f-11e7-aefb-f1890390432e'
}; };
module.exports = CHECKSUM; module.exports = CHECKSUM;

View file

@ -9,6 +9,37 @@ var Alpha = {
_alpha: 1, _alpha: 1,
_alphaTL: 1,
_alphaTR: 1,
_alphaBL: 1,
_alphaBR: 1,
clearAlpha: function ()
{
return this.setAlpha(1);
},
setAlpha: function (topLeft, topRight, bottomLeft, bottomRight)
{
if (topLeft === undefined) { topLeft = 1; }
// Treat as if there is only one alpha value for the whole Game Object
if (topRight === undefined)
{
this.alpha = topLeft;
}
else
{
this._alphaTL = Clamp(topLeft, 0, 1);
this._alphaTR = Clamp(topRight, 0, 1);
this._alphaBL = Clamp(bottomLeft, 0, 1);
this._alphaBR = Clamp(bottomRight, 0, 1);
}
return this;
},
// Global Alpha value. If changed this adjusts all alpha properties (topLeft, topRight, etc)
alpha: { alpha: {
get: function () get: function ()
@ -18,9 +49,15 @@ var Alpha = {
set: function (value) set: function (value)
{ {
this._alpha = Clamp(value, 0, 1); var v = Clamp(value, 0, 1);
if (this._alpha === 0) this._alpha = v;
this._alphaTL = v;
this._alphaTR = v;
this._alphaBL = v;
this._alphaBR = v;
if (v === 0)
{ {
this.renderFlags &= ~_FLAG; this.renderFlags &= ~_FLAG;
} }
@ -32,11 +69,89 @@ var Alpha = {
}, },
setAlpha: function (value) // Adjusts the alpha value of the top-left vertex (WebGL only)
{ alphaTopLeft: {
this.alpha = value;
get: function ()
{
return this._alphaTL;
},
set: function (value)
{
var v = Clamp(value, 0, 1);
this._alphaTL = v
if (v !== 0)
{
this.renderFlags |= _FLAG;
}
}
},
alphaTopRight: {
get: function ()
{
return this._alphaTR;
},
set: function (value)
{
var v = Clamp(value, 0, 1);
this._alphaTR = v
if (v !== 0)
{
this.renderFlags |= _FLAG;
}
}
},
alphaBottomLeft: {
get: function ()
{
return this._alphaBL;
},
set: function (value)
{
var v = Clamp(value, 0, 1);
this._alphaBL = v
if (v !== 0)
{
this.renderFlags |= _FLAG;
}
}
},
alphaBottomRight: {
get: function ()
{
return this._alphaBR;
},
set: function (value)
{
var v = Clamp(value, 0, 1);
this._alphaBR = v
if (v !== 0)
{
this.renderFlags |= _FLAG;
}
}
return this;
} }
}; };

View file

@ -461,7 +461,10 @@ var SpriteBatch = new Class({
var cameraMatrix = camera.matrix.matrix; var cameraMatrix = camera.matrix.matrix;
var mva, mvb, mvc, mvd, mve, mvf, tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3; var mva, mvb, mvc, mvd, mve, mvf, tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3;
var sra, srb, src, srd, sre, srf, cma, cmb, cmc, cmd, cme, cmf; var sra, srb, src, srd, sre, srf, cma, cmb, cmc, cmd, cme, cmf;
var alpha = gameObject.alpha; var alphaTL = gameObject._alphaTL;
var alphaTR = gameObject._alphaTR;
var alphaBL = gameObject._alphaBL;
var alphaBR = gameObject._alphaBR;
var tintTL = gameObject._tintTL; var tintTL = gameObject._tintTL;
var tintTR = gameObject._tintTR; var tintTR = gameObject._tintTR;
var tintBL = gameObject._tintBL; var tintBL = gameObject._tintBL;
@ -511,7 +514,7 @@ var SpriteBatch = new Class({
vertexBufferObjectF32[vertexOffset++] = 0; vertexBufferObjectF32[vertexOffset++] = 0;
vertexBufferObjectF32[vertexOffset++] = 0; vertexBufferObjectF32[vertexOffset++] = 0;
vertexBufferObjectU32[vertexOffset++] = tintTL; vertexBufferObjectU32[vertexOffset++] = tintTL;
vertexBufferObjectF32[vertexOffset++] = alpha; vertexBufferObjectF32[vertexOffset++] = alphaTL;
// Bottom Left // Bottom Left
vertexBufferObjectF32[vertexOffset++] = tx1; vertexBufferObjectF32[vertexOffset++] = tx1;
@ -519,7 +522,7 @@ var SpriteBatch = new Class({
vertexBufferObjectF32[vertexOffset++] = 0; vertexBufferObjectF32[vertexOffset++] = 0;
vertexBufferObjectF32[vertexOffset++] = 1; vertexBufferObjectF32[vertexOffset++] = 1;
vertexBufferObjectU32[vertexOffset++] = tintBL; vertexBufferObjectU32[vertexOffset++] = tintBL;
vertexBufferObjectF32[vertexOffset++] = alpha; vertexBufferObjectF32[vertexOffset++] = alphaBL;
// Bottom Right // Bottom Right
vertexBufferObjectF32[vertexOffset++] = tx2; vertexBufferObjectF32[vertexOffset++] = tx2;
@ -527,7 +530,7 @@ var SpriteBatch = new Class({
vertexBufferObjectF32[vertexOffset++] = 1; vertexBufferObjectF32[vertexOffset++] = 1;
vertexBufferObjectF32[vertexOffset++] = 1; vertexBufferObjectF32[vertexOffset++] = 1;
vertexBufferObjectU32[vertexOffset++] = tintBR; vertexBufferObjectU32[vertexOffset++] = tintBR;
vertexBufferObjectF32[vertexOffset++] = alpha; vertexBufferObjectF32[vertexOffset++] = alphaBR;
// Top Right // Top Right
vertexBufferObjectF32[vertexOffset++] = tx3; vertexBufferObjectF32[vertexOffset++] = tx3;
@ -535,7 +538,7 @@ var SpriteBatch = new Class({
vertexBufferObjectF32[vertexOffset++] = 1; vertexBufferObjectF32[vertexOffset++] = 1;
vertexBufferObjectF32[vertexOffset++] = 0; vertexBufferObjectF32[vertexOffset++] = 0;
vertexBufferObjectU32[vertexOffset++] = tintTR; vertexBufferObjectU32[vertexOffset++] = tintTR;
vertexBufferObjectF32[vertexOffset++] = alpha; vertexBufferObjectF32[vertexOffset++] = alphaTR;
}, },
addSprite: function (gameObject, camera) addSprite: function (gameObject, camera)
@ -565,7 +568,10 @@ var SpriteBatch = new Class({
var cameraMatrix = camera.matrix.matrix; var cameraMatrix = camera.matrix.matrix;
var mva, mvb, mvc, mvd, mve, mvf, tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3; var mva, mvb, mvc, mvd, mve, mvf, tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3;
var sra, srb, src, srd, sre, srf, cma, cmb, cmc, cmd, cme, cmf; var sra, srb, src, srd, sre, srf, cma, cmb, cmc, cmd, cme, cmf;
var alpha = gameObject.alpha; var alphaTL = gameObject._alphaTL;
var alphaTR = gameObject._alphaTR;
var alphaBL = gameObject._alphaBL;
var alphaBR = gameObject._alphaBR;
var tintTL = gameObject._tintTL; var tintTL = gameObject._tintTL;
var tintTR = gameObject._tintTR; var tintTR = gameObject._tintTR;
var tintBL = gameObject._tintBL; var tintBL = gameObject._tintBL;
@ -615,7 +621,7 @@ var SpriteBatch = new Class({
vertexBufferObjectF32[vertexOffset++] = uvs.x0; vertexBufferObjectF32[vertexOffset++] = uvs.x0;
vertexBufferObjectF32[vertexOffset++] = uvs.y0; vertexBufferObjectF32[vertexOffset++] = uvs.y0;
vertexBufferObjectU32[vertexOffset++] = tintTL; vertexBufferObjectU32[vertexOffset++] = tintTL;
vertexBufferObjectF32[vertexOffset++] = alpha; vertexBufferObjectF32[vertexOffset++] = alphaTL;
// Bottom Left // Bottom Left
vertexBufferObjectF32[vertexOffset++] = tx1; vertexBufferObjectF32[vertexOffset++] = tx1;
@ -623,7 +629,7 @@ var SpriteBatch = new Class({
vertexBufferObjectF32[vertexOffset++] = uvs.x1; vertexBufferObjectF32[vertexOffset++] = uvs.x1;
vertexBufferObjectF32[vertexOffset++] = uvs.y1; vertexBufferObjectF32[vertexOffset++] = uvs.y1;
vertexBufferObjectU32[vertexOffset++] = tintBL; vertexBufferObjectU32[vertexOffset++] = tintBL;
vertexBufferObjectF32[vertexOffset++] = alpha; vertexBufferObjectF32[vertexOffset++] = alphaBL;
// Bottom Right // Bottom Right
vertexBufferObjectF32[vertexOffset++] = tx2; vertexBufferObjectF32[vertexOffset++] = tx2;
@ -631,7 +637,7 @@ var SpriteBatch = new Class({
vertexBufferObjectF32[vertexOffset++] = uvs.x2; vertexBufferObjectF32[vertexOffset++] = uvs.x2;
vertexBufferObjectF32[vertexOffset++] = uvs.y2; vertexBufferObjectF32[vertexOffset++] = uvs.y2;
vertexBufferObjectU32[vertexOffset++] = tintBR; vertexBufferObjectU32[vertexOffset++] = tintBR;
vertexBufferObjectF32[vertexOffset++] = alpha; vertexBufferObjectF32[vertexOffset++] = alphaBR;
// Top Right // Top Right
vertexBufferObjectF32[vertexOffset++] = tx3; vertexBufferObjectF32[vertexOffset++] = tx3;
@ -639,7 +645,7 @@ var SpriteBatch = new Class({
vertexBufferObjectF32[vertexOffset++] = uvs.x3; vertexBufferObjectF32[vertexOffset++] = uvs.x3;
vertexBufferObjectF32[vertexOffset++] = uvs.y3; vertexBufferObjectF32[vertexOffset++] = uvs.y3;
vertexBufferObjectU32[vertexOffset++] = tintTR; vertexBufferObjectU32[vertexOffset++] = tintTR;
vertexBufferObjectF32[vertexOffset++] = alpha; vertexBufferObjectF32[vertexOffset++] = alphaTR;
} }
}); });