phaser/Phaser/system/animation/FrameData.ts

135 lines
2.6 KiB
TypeScript
Raw Normal View History

2013-04-12 16:19:56 +00:00
/// <reference path="../../Game.ts" />
2013-04-18 13:16:18 +00:00
/**
2013-04-18 15:49:08 +00:00
* Phaser - FrameData
*
* FrameData is a container for Frame objects, the internal representation of animation data in Phaser.
2013-04-18 13:16:18 +00:00
*/
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 FrameData {
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
constructor() {
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
this._frames = [];
this._frameNames = [];
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
}
private _frames: Frame[];
private _frameNames;
public get total(): number {
return this._frames.length;
}
public addFrame(frame: Frame): Frame {
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
frame.index = this._frames.length;
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
this._frames.push(frame);
2013-04-18 13:16:18 +00:00
if (frame.name !== '')
{
this._frameNames[frame.name] = frame.index;
}
return frame;
2013-04-12 16:19:56 +00:00
}
2013-04-18 13:16:18 +00:00
public getFrame(index: number): Frame {
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
if (this._frames[index])
{
return this._frames[index];
}
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
return null;
}
2013-04-18 13:16:18 +00:00
public getFrameByName(name: string): Frame {
2013-04-18 13:16:18 +00:00
if (this._frameNames[name] >= 0)
{
return this._frames[this._frameNames[name]];
}
2013-04-18 13:16:18 +00:00
return null;
2013-04-12 16:19:56 +00:00
}
2013-04-18 13:16:18 +00:00
public checkFrameName(name: string): bool {
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
if (this._frameNames[name] >= 0)
{
return true;
}
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
return false;
2013-04-12 16:19:56 +00:00
}
2013-04-18 13:16:18 +00:00
public getFrameRange(start: number, end: number, output?: Frame[] = []): Frame[] {
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
for (var i = start; i <= end; i++)
{
output.push(this._frames[i]);
}
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
return output;
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
}
public getFrameIndexes(output?: number[] = []): number[] {
output.length = 0;
for (var i = 0; i < this._frames.length; i++)
{
output.push(i);
}
return output;
2013-04-12 16:19:56 +00:00
}
2013-04-18 13:16:18 +00:00
public getFrameIndexesByName(input: string[]): number[] {
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
var output: number[] = [];
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
for (var i = 0; i < input.length; i++)
{
if (this.getFrameByName(input[i]))
{
output.push(this.getFrameByName(input[i]).index);
}
}
2013-04-12 16:19:56 +00:00
2013-04-18 13:16:18 +00:00
return output;
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
public getAllFrames(): Frame[] {
return this._frames;
2013-04-12 16:19:56 +00:00
}
2013-04-18 13:16:18 +00:00
public getFrames(range: number[]) {
var output: Frame[] = [];
for (var i = 0; i < range.length; i++)
{
output.push(this._frames[i]);
}
return output;
}
2013-04-12 16:19:56 +00:00
}
}