2013-08-08 18:16:47 +00:00
|
|
|
/// <reference path="../_definitions.ts" />
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
/**
|
2013-08-09 02:12:33 +00:00
|
|
|
* Frame
|
|
|
|
*
|
|
|
|
* A Frame is a single frame of an animation and is part of a FrameData collection.
|
|
|
|
*
|
|
|
|
* @package Phaser.Frame
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2013 Photon Storm Ltd.
|
|
|
|
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
|
|
|
*/
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
module Phaser {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
export class Frame {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Frame constructor
|
|
|
|
* Create a new <code>Frame</code> with specific position, size and name.
|
|
|
|
*
|
2013-05-04 11:56:33 +00:00
|
|
|
* @param x {number} X position within the image to cut from.
|
|
|
|
* @param y {number} Y position within the image to cut from.
|
|
|
|
* @param width {number} Width of the frame.
|
|
|
|
* @param height {number} Height of the frame.
|
|
|
|
* @param name {string} Name of this frame.
|
2013-05-03 11:32:39 +00:00
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
constructor(x: number, y: number, width: number, height: number, name: string) {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
this.name = name;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this.rotated = false;
|
|
|
|
this.trimmed = false;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-15 14:42:13 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* X position within the image to cut from.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public x: number;
|
2013-05-23 02:08:57 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Y position within the image to cut from.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public y: number;
|
2013-05-23 02:08:57 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Width of the frame.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public width: number;
|
2013-05-23 02:08:57 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Height of the frame.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public height: number;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Useful for Sprite Sheets.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public index: number;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Useful for Texture Atlas files. (is set to the filename value)
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public name: string = '';
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Rotated? (not yet implemented)
|
|
|
|
*/
|
2013-08-13 03:22:24 +00:00
|
|
|
public rotated: bool = false;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Either cw or ccw, rotation is always 90 degrees.
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public rotationDirection: string = 'cw';
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Was it trimmed when packed?
|
2013-08-13 03:22:24 +00:00
|
|
|
* @type {bool}
|
2013-05-03 11:32:39 +00:00
|
|
|
*/
|
2013-08-13 03:22:24 +00:00
|
|
|
public trimmed: bool;
|
2013-04-18 13:16:18 +00:00
|
|
|
|
|
|
|
// The coordinates of the trimmed sprite inside the original sprite
|
2013-05-23 02:08:57 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Width of the original sprite.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public sourceSizeW: number;
|
2013-05-23 02:08:57 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Height of the original sprite.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public sourceSizeH: number;
|
2013-05-23 02:08:57 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* X position of the trimmed sprite inside original sprite.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public spriteSourceSizeX: number;
|
2013-05-23 02:08:57 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Y position of the trimmed sprite inside original sprite.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public spriteSourceSizeY: number;
|
2013-05-23 02:08:57 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Width of the trimmed sprite.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public spriteSourceSizeW: number;
|
2013-05-23 02:08:57 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Height of the trimmed sprite.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public spriteSourceSizeH: number;
|
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Set rotation of this frame. (Not yet supported!)
|
|
|
|
*/
|
2013-08-13 03:22:24 +00:00
|
|
|
public setRotation(rotated: bool, rotationDirection: string) {
|
2013-04-18 13:16:18 +00:00
|
|
|
// Not yet supported
|
|
|
|
}
|
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Set trim of the frame.
|
2013-08-13 03:22:24 +00:00
|
|
|
* @param trimmed {bool} Whether this frame trimmed or not.
|
2013-05-04 11:56:33 +00:00
|
|
|
* @param actualWidth {number} Actual width of this frame.
|
|
|
|
* @param actualHeight {number} Actual height of this frame.
|
2013-06-03 11:03:34 +00:00
|
|
|
* @param destX {number} Destination x position.
|
|
|
|
* @param destY {number} Destination y position.
|
|
|
|
* @param destWidth {number} Destination draw width.
|
|
|
|
* @param destHeight {number} Destination draw height.
|
2013-05-03 11:32:39 +00:00
|
|
|
*/
|
2013-08-13 03:22:24 +00:00
|
|
|
public setTrim(trimmed: bool, actualWidth: number, actualHeight: number, destX: number, destY: number, destWidth: number, destHeight: number) {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
//console.log('setTrim', trimmed, 'aw', actualWidth, 'ah', actualHeight, 'dx', destX, 'dy', destY, 'dw', destWidth, 'dh', destHeight);
|
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this.trimmed = trimmed;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (trimmed)
|
|
|
|
{
|
|
|
|
this.width = actualWidth;
|
|
|
|
this.height = actualHeight;
|
|
|
|
this.sourceSizeW = actualWidth;
|
|
|
|
this.sourceSizeH = actualHeight;
|
|
|
|
this.spriteSourceSizeX = destX;
|
|
|
|
this.spriteSourceSizeY = destY;
|
|
|
|
this.spriteSourceSizeW = destWidth;
|
|
|
|
this.spriteSourceSizeH = destHeight;
|
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|