phaser/Phaser/animation/Frame.ts

169 lines
4.6 KiB
TypeScript
Raw Normal View History

/// <reference path="../_definitions.ts" />
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +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.
*
* @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-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-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-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-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)
*/
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?
* @type {bool}
2013-05-03 11:32:39 +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-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-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-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-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-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-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!)
*/
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.
* @param trimmed {bool} Whether this frame trimmed or not.
* @param actualWidth {number} Actual width of this frame.
* @param actualHeight {number} Actual height of this frame.
* @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
*/
public setTrim(trimmed: bool, actualWidth: number, actualHeight: number, destX: number, destY: number, destWidth: number, destHeight: number) {
2013-04-12 16:19:56 +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
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
}