Updated UV values

This commit is contained in:
Richard Davey 2018-07-02 23:51:42 +01:00
parent 265852fc75
commit c82c09914e
2 changed files with 53 additions and 49 deletions

View file

@ -51,6 +51,11 @@ The Texture Tint Pipeline has been rewritten to tidy up hundreds of lines of dup
* The `batchText` method has been removed from the `TextureTintPipeline` class, because it is now handled internally by the Game Object itself.
* The `batchDynamicTilemapLayer` method has been removed from the `TextureTintPipeline` class, because it is now handled internally by the Game Object itself.
Due to the changes in the Texture Tint Pipeline the Texture Frame class has also been updated. The following changes concern the Frame UV data:
* Previously, the UV data spanned 8 properties: `x0`, `y0`, `x1`, `y1`, `x2`, `y2`, `x3` and `y3` and was stored in the `data.uvs` object. These have been replaced with directly accessible properties: `u0`, `v0`, `u1` and `v1`. These 4 properties are used directly in all renderer code now. Although it was clearer having 8 properties, 4 of them were just duplicates, so we've traded a little clarity for a smaller overall object and less dictionary look-ups.
* `Frame.uvs` (and the corresponding `Frame.data.uvs`) object has been removed.
### New Tint Effects
As well as tidying the Texture Tint Pipeline, I also updated the shader. It now has a new attribute 'tintEffect' which allows you to control how a tint is applied to a Game Object. The default way tinting worked was for the tint color values to be multiplied with the texture pixel values. This meant you were unable to do things like tint a Game Object white, because multiplying a color by white doesn't change it. The new tint mode allows you to literally replace the pixel color values.

View file

@ -255,6 +255,46 @@ var Frame = new Class({
*/
this.customData = {};
/**
* WebGL UV u0 value.
*
* @name Phaser.Textures.Frame#u0
* @type {number}
* @default 0
* @since 3.11.0
*/
this.u0 = 0;
/**
* WebGL UV v0 value.
*
* @name Phaser.Textures.Frame#v0
* @type {number}
* @default 0
* @since 3.11.0
*/
this.v0 = 0;
/**
* WebGL UV u1 value.
*
* @name Phaser.Textures.Frame#u1
* @type {number}
* @default 0
* @since 3.11.0
*/
this.u1 = 0;
/**
* WebGL UV v1 value.
*
* @name Phaser.Textures.Frame#v1
* @type {number}
* @default 0
* @since 3.11.0
*/
this.v1 = 0;
/**
* The un-modified source frame, trim and UV data.
*
@ -283,16 +323,6 @@ var Frame = new Class({
w: 0,
h: 0
},
uvs: {
x0: 0,
y0: 0,
x1: 0,
y1: 0,
x2: 0,
y2: 0,
x3: 0,
y3: 0
},
radius: 0,
drawImage: {
sx: 0,
@ -448,19 +478,12 @@ var Frame = new Class({
var tw = this.source.width;
var th = this.source.height;
var uvs = this.data.uvs;
uvs.x0 = cx / tw;
uvs.y0 = cy / th;
this.u0 = cx / tw;
this.v0 = cy / th;
uvs.x1 = cx / tw;
uvs.y1 = (cy + ch) / th;
uvs.x2 = (cx + cw) / tw;
uvs.y2 = (cy + ch) / th;
uvs.x3 = (cx + cw) / tw;
uvs.y3 = cy / th;
this.u1 = (cx + cw) / tw;
this.v1 = (cy + ch) / th;
return this;
},
@ -477,19 +500,12 @@ var Frame = new Class({
{
var tw = this.source.width;
var th = this.source.height;
var uvs = this.data.uvs;
uvs.x3 = (this.cutX + this.cutHeight) / tw;
uvs.y3 = (this.cutY + this.cutWidth) / th;
this.u0 = (this.cutX + this.cutHeight) / tw;
this.v0 = this.cutY / th;
uvs.x2 = this.cutX / tw;
uvs.y2 = (this.cutY + this.cutWidth) / th;
uvs.x1 = this.cutX / tw;
uvs.y1 = this.cutY / th;
uvs.x0 = (this.cutX + this.cutHeight) / tw;
uvs.y0 = this.cutY / th;
this.u1 = this.cutX / tw;
this.v1 = (this.cutY + this.cutWidth) / th;
return this;
},
@ -581,23 +597,6 @@ var Frame = new Class({
},
/**
* The UV data for this Frame.
*
* @name Phaser.Textures.Frame#uvs
* @type {object}
* @readOnly
* @since 3.0.0
*/
uvs: {
get: function ()
{
return this.data.uvs;
}
},
/**
* The radius of the Frame (derived from sqrt(w * w + h * h) / 2)
*