Finish document for Time, Tween, Animation, AnimationLoader, Frame.

This commit is contained in:
Sean
2013-05-10 16:31:16 +01:00
committed by Richard Davey
parent e88c48641d
commit 00ef200914
5 changed files with 251 additions and 50 deletions
+77 -2
View File
@@ -14,8 +14,12 @@ module Phaser {
* Animation constructor
* Create a new <code>Animation</code>.
*
* @param width Width of the world bound.
* @param height Height of the world bound.
* @param parent {Sprite} Owner sprite of this animation.
* @param frameData {FrameData} The FrameData object contains animation data.
* @param name {string} Unique name of this animation.
* @param frames {number[]/string[]} An array of numbers or strings indicating what frames to play in what order.
* @param delay {number} Time between frames in ms.
* @param looped {boolean} Whether or not the animation is looped or just plays once.
*/
constructor(game: Game, parent: Sprite, frameData: FrameData, name: string, frames, delay: number, looped: bool) {
@@ -36,21 +40,72 @@ module Phaser {
}
/**
* Local private reference to game.
*/
private _game: Game;
/**
* Local private reference to its owner sprite.
* @type {Sprite}
*/
private _parent: Sprite;
/**
* Animation frame container.
* @type {number[]}
*/
private _frames: number[];
/**
* Frame data of this animation.(parsed from sprite sheet)
* @type {FrameData}
*/
private _frameData: FrameData;
/**
* Index of current frame.
* @type {number}
*/
private _frameIndex: number;
/**
* Time when switched to last frame (in ms).
* @type number
*/
private _timeLastFrame: number;
/**
* Time when this will switch to next frame (in ms).
* @type number
*/
private _timeNextFrame: number;
/**
* Name of this animation.
* @type {string}
*/
public name: string;
/**
* Currently played frame instance.
* @type {Frame}
*/
public currentFrame: Frame;
/**
* Whether or not this animation finished playing.
* @type {boolean}
*/
public isFinished: bool;
/**
* Whethor or not this animation is currently playing.
* @type {boolean}
*/
public isPlaying: bool;
/**
* Whether or not the animation is looped.
* @type {boolean}
*/
public looped: bool;
/**
* Time between frames in ms.
* @type {number}
*/
public delay: number;
public get frameTotal(): number {
@@ -74,6 +129,11 @@ module Phaser {
}
/**
* Play this animation.
* @param frameRate {number} FrameRate you want to specify instead of using default.
* @param loop {boolean} Whether or not the animation is looped or just plays once.
*/
public play(frameRate?: number = null, loop?: bool) {
if (frameRate !== null)
@@ -97,6 +157,9 @@ module Phaser {
}
/**
* Play this animation from the first frame.
*/
public restart() {
this.isPlaying = true;
@@ -110,6 +173,9 @@ module Phaser {
}
/**
* Stop playing animation and set it finished.
*/
public stop() {
this.isPlaying = false;
@@ -117,6 +183,9 @@ module Phaser {
}
/**
* Update animation frames.
*/
public update(): bool {
if (this.isPlaying == true && this._game.time.now >= this._timeNextFrame)
@@ -150,6 +219,9 @@ module Phaser {
}
/**
* Clean up animation memory.
*/
public destroy() {
this._game = null;
@@ -161,6 +233,9 @@ module Phaser {
}
/**
* Animation complete callback method.
*/
private onComplete() {
this.isPlaying = false;
+7 -7
View File
@@ -12,11 +12,11 @@ module Phaser {
/**
* Parse a sprite sheet from asset data.
* @param key Asset key for the sprite sheet data.
* @param frameWidth Width of animation frame.
* @param frameHeight Height of animation frame.
* @param frameMax Number of animation frames.
* @return {FrameData=} Generated FrameData object.
* @param key {string} Asset key for the sprite sheet data.
* @param frameWidth {number} Width of animation frame.
* @param frameHeight {number} Height of animation frame.
* @param frameMax {number} Number of animation frames.
* @return {FrameData} Generated FrameData object.
*/
public static parseSpriteSheet(game: Game, key: string, frameWidth: number, frameHeight: number, frameMax: number): FrameData {
@@ -73,8 +73,8 @@ module Phaser {
/**
* Parse frame datas from json.
* @param json Json data you want to parse.
* @return {FrameData=} Generated FrameData object.
* @param json {object} Json data you want to parse.
* @return {FrameData} Generated FrameData object.
*/
public static parseJSONData(game: Game, json): FrameData {
+12 -12
View File
@@ -14,11 +14,11 @@ module Phaser {
* Frame constructor
* Create a new <code>Frame</code> with specific position, size and name.
*
* @param x X position within the image to cut from.
* @param y Y position within the image to cut from.
* @param width Width of the frame.
* @param height Height of the frame.
* @param name Name of this frame.
* @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.
*/
constructor(x: number, y: number, width: number, height: number, name: string) {
@@ -122,13 +122,13 @@ module Phaser {
/**
* Set trim of the frame.
* @param trimmed Whether this frame trimmed or not.
* @param actualWidth Actual width of this frame.
* @param actualHeight Actual height of this frame.
* @param destX Destiny x position.
* @param destY Destiny y position.
* @param destWidth Destiny draw width.
* @param destHeight Destiny draw height.
* @param trimmed {boolean} 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} Destiny x position.
* @param destY {number} Destiny y position.
* @param destWidth {number} Destiny draw width.
* @param destHeight {number} Destiny draw height.
*/
public setTrim(trimmed: bool, actualWidth, actualHeight, destX, destY, destWidth, destHeight, ) {