2016-09-29 15:10:22 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Frame is a section of a Texture.
|
2016-10-11 13:52:17 +00:00
|
|
|
*
|
2016-09-29 15:10:22 +00:00
|
|
|
* Called TextureFrame during integration, will rename to Frame later.
|
|
|
|
*
|
|
|
|
* @class Phaser.TextureFrame
|
|
|
|
* @constructor
|
|
|
|
* @param {Phaser.Texture} texture - The Texture this Frame belongs to.
|
|
|
|
* @param {string} name - The unique (within the Texture) name of this Frame.
|
|
|
|
* @param {number} x - X position of the frame within the Texture.
|
|
|
|
* @param {number} y - Y position of the frame within the Texture.
|
|
|
|
* @param {number} width - Width of the frame within the Texture.
|
|
|
|
* @param {number} height - Height of the frame within the Texture.
|
|
|
|
*/
|
2016-09-30 05:07:00 +00:00
|
|
|
Phaser.TextureFrame = function (texture, name, sourceIndex, x, y, width, height)
|
2016-09-29 15:10:22 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Texture} texture - The Texture this frame belongs to.
|
|
|
|
*/
|
|
|
|
this.texture = texture;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {string} name - The name of this frame within the Texture.
|
|
|
|
*/
|
|
|
|
this.name = name;
|
|
|
|
|
2016-11-07 00:33:18 +00:00
|
|
|
this.source = texture.source[sourceIndex];
|
|
|
|
|
|
|
|
this.sourceIndex = sourceIndex;
|
|
|
|
|
2016-09-29 15:10:22 +00:00
|
|
|
/**
|
|
|
|
* @property {number} cutX - X position within the source image to cut from.
|
|
|
|
*/
|
|
|
|
this.cutX = x;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} cutY - Y position within the source image to cut from.
|
|
|
|
*/
|
|
|
|
this.cutY = y;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} cutWidth - The width of the area in the source image to cut.
|
|
|
|
*/
|
|
|
|
this.cutWidth = width;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} cutHeight - The height of the area in the source image to cut.
|
|
|
|
*/
|
|
|
|
this.cutHeight = height;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} x - The X rendering offset of this Frame, taking trim into account.
|
|
|
|
*/
|
|
|
|
this.x = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} y - The Y rendering offset of this Frame, taking trim into account.
|
|
|
|
*/
|
|
|
|
this.y = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} width - The rendering width of this Frame, taking trim into account.
|
|
|
|
*/
|
|
|
|
this.width = width;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} height - The rendering height of this Frame, taking trim into account.
|
|
|
|
*/
|
|
|
|
this.height = height;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this frame is rotated or not in the Texture?
|
|
|
|
* Rotation allows you to use rotated frames in texture atlas packing.
|
|
|
|
* It has nothing to do with Sprite rotation.
|
2016-10-11 13:52:17 +00:00
|
|
|
*
|
2016-09-29 15:10:22 +00:00
|
|
|
* @property {boolean} rotated
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.rotated = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this a tiling texture? As used by the likes of a TilingSprite.
|
2016-10-11 13:52:17 +00:00
|
|
|
* TODO: Try and remove this, it shouldn't be here
|
2016-09-29 15:10:22 +00:00
|
|
|
*
|
|
|
|
* @property {boolean} isTiling
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.isTiling = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This will let a renderer know that a tinted parent has updated its texture.
|
2016-10-11 13:52:17 +00:00
|
|
|
* TODO: Try and remove this, it shouldn't be here
|
2016-09-29 15:10:22 +00:00
|
|
|
*
|
|
|
|
* @property {boolean} requiresReTint
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.requiresReTint = false;
|
|
|
|
|
2016-10-11 13:52:17 +00:00
|
|
|
// Over-rides the Renderer setting? -1 = use Renderer Setting, 0 = No rounding, 1 = Round
|
|
|
|
this.autoRound = -1;
|
2016-10-03 11:44:54 +00:00
|
|
|
|
2016-09-29 15:10:22 +00:00
|
|
|
/**
|
|
|
|
* The un-modified source frame, trim and UV data.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @property {object} data
|
|
|
|
*/
|
|
|
|
this.data = {
|
|
|
|
cut: {
|
|
|
|
x: x,
|
|
|
|
y: y,
|
|
|
|
w: width,
|
|
|
|
h: height,
|
|
|
|
r: x + width,
|
|
|
|
b: y + height
|
|
|
|
},
|
2016-10-19 13:30:23 +00:00
|
|
|
trim: false,
|
2016-09-29 15:10:22 +00:00
|
|
|
sourceSize: {
|
|
|
|
w: width,
|
|
|
|
h: height
|
|
|
|
},
|
|
|
|
spriteSourceSize: {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
w: width,
|
|
|
|
h: height
|
|
|
|
},
|
|
|
|
uvs: {
|
|
|
|
x0: 0,
|
|
|
|
y0: 0,
|
|
|
|
x1: 0,
|
|
|
|
y1: 0,
|
|
|
|
x2: 0,
|
|
|
|
y2: 0,
|
|
|
|
x3: 0,
|
|
|
|
y3: 0
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-18 16:03:25 +00:00
|
|
|
this.updateUVs();
|
2016-09-29 15:10:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.TextureFrame.prototype.constructor = Phaser.TextureFrame;
|
|
|
|
|
|
|
|
Phaser.TextureFrame.prototype = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the frame was trimmed when added to the Texture Atlas, this records the trim and source data.
|
|
|
|
*
|
|
|
|
* @method Phaser.TextureFrame#setTrim
|
|
|
|
* @param {number} actualWidth - The width of the frame before being trimmed.
|
|
|
|
* @param {number} actualHeight - The height of the frame before being trimmed.
|
|
|
|
* @param {number} destX - The destination X position of the trimmed frame for display.
|
|
|
|
* @param {number} destY - The destination Y position of the trimmed frame for display.
|
|
|
|
* @param {number} destWidth - The destination width of the trimmed frame for display.
|
|
|
|
* @param {number} destHeight - The destination height of the trimmed frame for display.
|
|
|
|
*/
|
|
|
|
setTrim: function (actualWidth, actualHeight, destX, destY, destWidth, destHeight)
|
|
|
|
{
|
|
|
|
// Store actual values
|
|
|
|
|
2016-10-19 13:30:23 +00:00
|
|
|
this.data.trim = true;
|
|
|
|
|
2016-09-29 15:10:22 +00:00
|
|
|
this.data.sourceSize.w = actualWidth;
|
|
|
|
this.data.sourceSize.h = actualHeight;
|
|
|
|
|
|
|
|
this.data.spriteSourceSize.x = destX;
|
|
|
|
this.data.spriteSourceSize.y = destY;
|
|
|
|
this.data.spriteSourceSize.w = destWidth;
|
|
|
|
this.data.spriteSourceSize.h = destHeight;
|
|
|
|
|
|
|
|
// Adjust properties
|
|
|
|
this.x = destX;
|
|
|
|
this.y = destY;
|
|
|
|
this.width = destWidth;
|
|
|
|
this.height = destHeight;
|
|
|
|
|
2016-10-18 16:03:25 +00:00
|
|
|
this.updateUVs();
|
|
|
|
|
2016-09-29 15:10:22 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the internal WebGL UV cache.
|
|
|
|
*
|
|
|
|
* @method updateUVs
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
updateUVs: function ()
|
|
|
|
{
|
2016-10-18 16:03:25 +00:00
|
|
|
var tw = this.source.width;
|
|
|
|
var th = this.source.height;
|
2016-09-29 15:10:22 +00:00
|
|
|
var uvs = this.data.uvs;
|
|
|
|
|
2016-10-18 16:03:25 +00:00
|
|
|
uvs.x0 = this.cutX / tw;
|
|
|
|
uvs.y0 = this.cutY / th;
|
2016-09-29 15:10:22 +00:00
|
|
|
|
2016-10-18 16:03:25 +00:00
|
|
|
uvs.x1 = (this.cutX + this.cutWidth) / tw;
|
|
|
|
uvs.y1 = this.cutY / th;
|
2016-09-29 15:10:22 +00:00
|
|
|
|
2016-10-18 16:03:25 +00:00
|
|
|
uvs.x2 = (this.cutX + this.cutWidth) / tw;
|
|
|
|
uvs.y2 = (this.cutY + this.cutHeight) / th;
|
2016-09-29 15:10:22 +00:00
|
|
|
|
2016-10-18 16:03:25 +00:00
|
|
|
uvs.x3 = this.cutX / tw;
|
|
|
|
uvs.y3 = (this.cutY + this.cutHeight) / th;
|
2016-09-29 15:10:22 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the internal WebGL UV cache.
|
|
|
|
*
|
|
|
|
* @method updateUVsInverted
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
updateUVsInverted: function ()
|
|
|
|
{
|
2016-10-18 16:03:25 +00:00
|
|
|
var tw = this.source.width;
|
|
|
|
var th = this.source.height;
|
2016-09-29 15:10:22 +00:00
|
|
|
var uvs = this.data.uvs;
|
|
|
|
|
2016-10-19 13:30:23 +00:00
|
|
|
uvs.x0 = this.cutX / tw;
|
|
|
|
uvs.y0 = this.cutY / th;
|
2016-09-29 15:10:22 +00:00
|
|
|
|
2016-10-19 13:30:23 +00:00
|
|
|
uvs.x1 = (this.cutX + this.cutHeight) / tw;
|
|
|
|
uvs.y1 = this.cutY / th;
|
2016-09-29 15:10:22 +00:00
|
|
|
|
2016-10-19 13:30:23 +00:00
|
|
|
uvs.x2 = (this.cutX + this.cutHeight) / tw;
|
|
|
|
uvs.y2 = (this.cutY + this.cutWidth) / th;
|
2016-09-29 15:10:22 +00:00
|
|
|
|
2016-10-19 13:30:23 +00:00
|
|
|
uvs.x3 = this.cutX / tw;
|
|
|
|
uvs.y3 = (this.cutY + this.cutWidth) / th;
|
2016-09-29 15:10:22 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
clone: function ()
|
|
|
|
{
|
2016-11-07 00:33:18 +00:00
|
|
|
var clone = new Phaser.TextureFrame(this.texture, this.name, this.sourceIndex);
|
2016-09-29 15:10:22 +00:00
|
|
|
|
2016-11-07 00:33:18 +00:00
|
|
|
clone.cutX = this.cutX;
|
|
|
|
clone.cutY = this.cutY;
|
|
|
|
clone.cutWidth = this.cutWidth;
|
|
|
|
clone.cutHeight = this.cutHeight;
|
2016-09-29 15:10:22 +00:00
|
|
|
|
2016-11-07 00:33:18 +00:00
|
|
|
clone.x = this.x;
|
|
|
|
clone.y = this.y;
|
|
|
|
clone.width = this.width;
|
|
|
|
clone.height = this.height;
|
2016-09-29 15:10:22 +00:00
|
|
|
|
2016-11-07 00:33:18 +00:00
|
|
|
clone.rotated = this.rotated;
|
2016-09-29 15:10:22 +00:00
|
|
|
|
2016-11-07 00:33:18 +00:00
|
|
|
clone.data = Phaser.Utils.extend(true, clone.data, this.data);
|
|
|
|
|
|
|
|
clone.updateUVs();
|
2016-09-29 15:10:22 +00:00
|
|
|
|
2016-11-07 00:33:18 +00:00
|
|
|
return clone;
|
2016-09-29 15:10:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.defineProperties(Phaser.TextureFrame.prototype, {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The width of the Frame in its un-trimmed, un-padded state, as prepared in the art package,
|
|
|
|
* before being packed.
|
|
|
|
*
|
|
|
|
* @name Phaser.TextureFrame#realWidth
|
|
|
|
* @property {any} realWidth
|
|
|
|
*/
|
|
|
|
realWidth: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.data.sourceSize.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of the Frame in its un-trimmed, un-padded state, as prepared in the art package,
|
|
|
|
* before being packed.
|
|
|
|
*
|
|
|
|
* @name Phaser.TextureFrame#realHeight
|
|
|
|
* @property {any} realHeight
|
|
|
|
*/
|
|
|
|
realHeight: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.data.sourceSize.h;
|
|
|
|
}
|
|
|
|
|
2016-10-18 16:03:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UVs
|
|
|
|
*
|
|
|
|
* @name Phaser.TextureFrame#uvs
|
|
|
|
* @property {Object} uvs
|
|
|
|
*/
|
|
|
|
uvs: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.data.uvs;
|
|
|
|
}
|
|
|
|
|
2016-09-29 15:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|