2013-08-28 06:02:55 +00:00
|
|
|
/**
|
2013-09-17 15:28:59 +00:00
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2016-04-04 21:15:01 +00:00
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-08-28 06:02:55 +00:00
|
|
|
* A Frame is a single frame of an animation and is part of a FrameData collection.
|
|
|
|
*
|
2013-10-03 01:38:35 +00:00
|
|
|
* @class Phaser.Frame
|
2013-09-17 15:28:59 +00:00
|
|
|
* @constructor
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {number} index - The index of this Frame within the FrameData set it is being added to.
|
|
|
|
* @param {number} x - X position of the frame within the texture image.
|
|
|
|
* @param {number} y - Y position of the frame within the texture image.
|
|
|
|
* @param {number} width - Width of the frame within the texture image.
|
|
|
|
* @param {number} height - Height of the frame within the texture image.
|
|
|
|
* @param {string} name - The name of the frame. In Texture Atlas data this is usually set to the filename.
|
2013-08-28 06:02:55 +00:00
|
|
|
*/
|
2015-04-21 04:11:19 +00:00
|
|
|
Phaser.Frame = function (index, x, y, width, height, name) {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {number} index - The index of this Frame within the FrameData set it is being added to.
|
|
|
|
*/
|
|
|
|
this.index = index;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {number} x - X position within the image to cut from.
|
|
|
|
*/
|
|
|
|
this.x = x;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} y - Y position within the image to cut from.
|
|
|
|
*/
|
|
|
|
this.y = y;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} width - Width of the frame.
|
|
|
|
*/
|
|
|
|
this.width = width;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} height - Height of the frame.
|
|
|
|
*/
|
|
|
|
this.height = height;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {string} name - Useful for Texture Atlas files (is set to the filename value).
|
|
|
|
*/
|
|
|
|
this.name = name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} centerX - Center X position within the image to cut from.
|
|
|
|
*/
|
2013-09-17 15:28:59 +00:00
|
|
|
this.centerX = Math.floor(width / 2);
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {number} centerY - Center Y position within the image to cut from.
|
|
|
|
*/
|
2013-09-17 15:28:59 +00:00
|
|
|
this.centerY = Math.floor(height / 2);
|
2013-09-10 19:40:34 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {number} distance - The distance from the top left to the bottom-right of this Frame.
|
|
|
|
*/
|
|
|
|
this.distance = Phaser.Math.distance(0, 0, width, height);
|
|
|
|
|
|
|
|
/**
|
2016-09-19 23:53:00 +00:00
|
|
|
* @property {boolean} rotated - Is the frame rotated in the source texture?
|
2013-11-25 03:13:04 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.rotated = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {boolean} trimmed - Was it trimmed when packed?
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.trimmed = false;
|
|
|
|
|
|
|
|
/**
|
2015-04-21 14:54:44 +00:00
|
|
|
* @property {number} sourceSizeW - Width of the original sprite before it was trimmed.
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2013-09-10 19:40:34 +00:00
|
|
|
this.sourceSizeW = width;
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2015-04-21 14:54:44 +00:00
|
|
|
* @property {number} sourceSizeH - Height of the original sprite before it was trimmed.
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2013-09-10 19:40:34 +00:00
|
|
|
this.sourceSizeH = height;
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {number} spriteSourceSizeX - X position of the trimmed sprite inside original sprite.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.spriteSourceSizeX = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} spriteSourceSizeY - Y position of the trimmed sprite inside original sprite.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.spriteSourceSizeY = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} spriteSourceSizeW - Width of the trimmed sprite.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.spriteSourceSizeW = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} spriteSourceSizeH - Height of the trimmed sprite.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.spriteSourceSizeH = 0;
|
2013-09-10 19:40:34 +00:00
|
|
|
|
2014-07-10 09:46:12 +00:00
|
|
|
/**
|
|
|
|
* @property {number} right - The right of the Frame (x + width).
|
|
|
|
*/
|
|
|
|
this.right = this.x + this.width;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} bottom - The bottom of the frame (y + height).
|
|
|
|
*/
|
|
|
|
this.bottom = this.y + this.height;
|
|
|
|
|
2013-09-10 19:40:34 +00:00
|
|
|
};
|
|
|
|
|
2013-10-03 01:38:35 +00:00
|
|
|
Phaser.Frame.prototype = {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-05-05 23:37:50 +00:00
|
|
|
/**
|
|
|
|
* Adjusts of all the Frame properties based on the given width and height values.
|
|
|
|
*
|
|
|
|
* @method Phaser.Frame#resize
|
|
|
|
* @param {integer} width - The new width of the Frame.
|
|
|
|
* @param {integer} height - The new height of the Frame.
|
|
|
|
*/
|
|
|
|
resize: function (width, height) {
|
|
|
|
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
this.centerX = Math.floor(width / 2);
|
|
|
|
this.centerY = Math.floor(height / 2);
|
|
|
|
this.distance = Phaser.Math.distance(0, 0, width, height);
|
|
|
|
this.sourceSizeW = width;
|
|
|
|
this.sourceSizeH = height;
|
|
|
|
this.right = this.x + width;
|
|
|
|
this.bottom = this.y + height;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* If the frame was trimmed when added to the Texture Atlas this records the trim and source data.
|
|
|
|
*
|
|
|
|
* @method Phaser.Frame#setTrim
|
|
|
|
* @param {boolean} trimmed - If this frame was trimmed or not.
|
|
|
|
* @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.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
setTrim: function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
|
|
|
|
|
|
|
|
this.trimmed = trimmed;
|
|
|
|
|
2013-09-03 14:35:40 +00:00
|
|
|
if (trimmed)
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
this.sourceSizeW = actualWidth;
|
|
|
|
this.sourceSizeH = actualHeight;
|
2013-11-25 03:13:04 +00:00
|
|
|
this.centerX = Math.floor(actualWidth / 2);
|
|
|
|
this.centerY = Math.floor(actualHeight / 2);
|
2013-08-28 06:02:55 +00:00
|
|
|
this.spriteSourceSizeX = destX;
|
|
|
|
this.spriteSourceSizeY = destY;
|
|
|
|
this.spriteSourceSizeW = destWidth;
|
|
|
|
this.spriteSourceSizeH = destHeight;
|
|
|
|
}
|
|
|
|
|
2014-02-06 19:34:05 +00:00
|
|
|
},
|
|
|
|
|
2014-09-02 20:03:16 +00:00
|
|
|
/**
|
|
|
|
* Clones this Frame into a new Phaser.Frame object and returns it.
|
2016-09-26 20:28:43 +00:00
|
|
|
* Note that all properties are cloned, including the name and index.
|
2014-09-02 20:03:16 +00:00
|
|
|
*
|
2014-11-25 00:20:41 +00:00
|
|
|
* @method Phaser.Frame#clone
|
2014-09-02 20:03:16 +00:00
|
|
|
* @return {Phaser.Frame} An exact copy of this Frame object.
|
|
|
|
*/
|
|
|
|
clone: function () {
|
|
|
|
|
2015-04-21 04:11:19 +00:00
|
|
|
var output = new Phaser.Frame(this.index, this.x, this.y, this.width, this.height, this.name);
|
2014-09-02 20:03:16 +00:00
|
|
|
|
|
|
|
for (var prop in this)
|
|
|
|
{
|
|
|
|
if (this.hasOwnProperty(prop))
|
|
|
|
{
|
|
|
|
output[prop] = this[prop];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-02-06 19:34:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a Rectangle set to the dimensions of this Frame.
|
|
|
|
*
|
|
|
|
* @method Phaser.Frame#getRect
|
|
|
|
* @param {Phaser.Rectangle} [out] - A rectangle to copy the frame dimensions to.
|
|
|
|
* @return {Phaser.Rectangle} A rectangle.
|
|
|
|
*/
|
|
|
|
getRect: function (out) {
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (out === undefined)
|
2014-02-06 19:34:05 +00:00
|
|
|
{
|
|
|
|
out = new Phaser.Rectangle(this.x, this.y, this.width, this.height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out.setTo(this.x, this.y, this.width, this.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2013-12-30 16:54:00 +00:00
|
|
|
|
|
|
|
Phaser.Frame.prototype.constructor = Phaser.Frame;
|