Skip to content

Commit 9da64e6

Browse files
pixelpicoseanphotonstorm
authored andcommitted
Finish document for AnimationManager, CameraManager, SoundManager and TweenManager class.
1 parent 98693cb commit 9da64e6

4 files changed

Lines changed: 182 additions & 1 deletion

File tree

Phaser/AnimationManager.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ module Phaser {
1616

1717
export class AnimationManager {
1818

19+
/**
20+
* AnimationManager constructor
21+
*
22+
* Create a new <code>AnimationManager</code>.
23+
*
24+
* @param parent Owner sprite of this manager.
25+
*/
1926
constructor(game: Game, parent: Sprite) {
2027

2128
this._game = game;
@@ -24,16 +31,43 @@ module Phaser {
2431

2532
}
2633

34+
/**
35+
* Local private reference to game.
36+
*/
2737
private _game: Game;
38+
/**
39+
* Local private reference to its owner sprite.
40+
*/
2841
private _parent: Sprite;
2942

43+
/**
44+
* Animation key-value container.
45+
*/
3046
private _anims: {};
47+
/**
48+
* Index of current frame.
49+
* @type {number}
50+
*/
3151
private _frameIndex: number;
52+
/**
53+
* Data contains animation frames.
54+
* @type {FrameData}
55+
*/
3256
private _frameData: FrameData = null;
3357

58+
/**
59+
* Keeps track of the current animation being played.
60+
*/
3461
public currentAnim: Animation;
62+
/**
63+
* Keeps track of the current frame of animation.
64+
*/
3565
public currentFrame: Frame = null;
3666

67+
/**
68+
* Load animation frame data.
69+
* @param frameData Data to be loaded.
70+
*/
3771
public loadFrameData(frameData: FrameData) {
3872

3973
this._frameData = frameData;
@@ -42,6 +76,14 @@ module Phaser {
4276

4377
}
4478

79+
/**
80+
* Add a new animation.
81+
* @param name What this animation should be called (e.g. "run").
82+
* @param frames An array of numbers/strings indicating what frames to play in what order (e.g. [1, 2, 3] or ['run0', 'run1', run2]).
83+
* @param frameRate The speed in frames per second that the animation should play at (e.g. 60 fps).
84+
* @param loop Whether or not the animation is looped or just plays once.
85+
* @param useNumericIndex Use number indexes instead of string indexes?
86+
*/
4587
public add(name: string, frames: any[] = null, frameRate: number = 60, loop: bool = false, useNumericIndex: bool = true) {
4688

4789
if (this._frameData == null)
@@ -98,6 +140,12 @@ module Phaser {
98140

99141
}
100142

143+
/**
144+
* Play animation with specific name.
145+
* @param name The string name of the animation you want to play.
146+
* @param frameRate FrameRate you want to specify instead of using default.
147+
* @param loop Whether or not the animation is looped or just plays once.
148+
*/
101149
public play(name: string, frameRate?: number = null, loop?: bool) {
102150

103151
if (this._anims[name])
@@ -118,6 +166,10 @@ module Phaser {
118166

119167
}
120168

169+
/**
170+
* Stop animation by name.
171+
* Current animation will be automatically set to the stopped one.
172+
*/
121173
public stop(name: string) {
122174

123175
if (this._anims[name])
@@ -128,6 +180,9 @@ module Phaser {
128180

129181
}
130182

183+
/**
184+
* Update animation and parent sprite's bounds.
185+
*/
131186
public update() {
132187

133188
if (this.currentAnim && this.currentAnim.update() == true)

Phaser/CameraManager.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ module Phaser {
1515

1616
export class CameraManager {
1717

18+
/**
19+
* CameraManager constructor
20+
* This will create a new <code>Camera</code> with position and size.
21+
*
22+
* @param x X Position of the created camera.
23+
* @param y y Position of the created camera.
24+
* @param width Width of the created camera.
25+
* @param height Height of the created camera.
26+
*/
1827
constructor(game: Game, x: number, y: number, width: number, height: number) {
1928

2029
this._game = game;
@@ -25,24 +34,56 @@ module Phaser {
2534

2635
}
2736

37+
/**
38+
* Local private reference to Game.
39+
*/
2840
private _game: Game;
41+
/**
42+
* Local container for storing camera.
43+
*/
2944
private _cameras: Camera[];
45+
/**
46+
* Local helper stores index of next created camera.
47+
*/
3048
private _cameraInstance: number = 0;
3149

50+
/**
51+
* Currently used camera.
52+
*/
3253
public current: Camera;
3354

55+
/**
56+
* Get all the cameras.
57+
*
58+
* @returns {array} An array contains all the cameras.
59+
*/
3460
public getAll(): Camera[] {
3561
return this._cameras;
3662
}
3763

64+
/**
65+
* Update cameras.
66+
*/
3867
public update() {
3968
this._cameras.forEach((camera) => camera.update());
4069
}
4170

71+
/**
72+
* Render cameras.
73+
*/
4274
public render() {
4375
this._cameras.forEach((camera) => camera.render());
4476
}
4577

78+
/**
79+
* Create a new camera with specific position and size.
80+
*
81+
* @param x X position of the new camera.
82+
* @param y Y position of the new camera.
83+
* @param width Width of the new camera.
84+
* @param height Height of the new camera.
85+
* @returns {Camera=} The newly created camera object.
86+
*/
4687
public addCamera(x: number, y: number, width: number, height: number): Camera {
4788

4889
var newCam: Camera = new Camera(this._game, this._cameraInstance, x, y, width, height);
@@ -55,6 +96,12 @@ module Phaser {
5596

5697
}
5798

99+
/**
100+
* Remove a new camera with its id.
101+
*
102+
* @param id ID of the camera you want to remove.
103+
* @returns {boolean} True if successfully removed the camera, otherwise return false.
104+
*/
58105
public removeCamera(id: number): bool {
59106

60107
for (var c = 0; c < this._cameras.length; c++)
@@ -76,6 +123,9 @@ module Phaser {
76123

77124
}
78125

126+
/**
127+
* Clean up memory.
128+
*/
79129
public destroy() {
80130

81131
this._cameras.length = 0;

Phaser/SoundManager.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ module Phaser {
1111

1212
export class SoundManager {
1313

14+
/**
15+
* SoundManager constructor
16+
*
17+
* Create a new <code>SoundManager</code>.
18+
*/
1419
constructor(game: Game) {
1520

1621
this._game = game;
@@ -36,18 +41,37 @@ module Phaser {
3641

3742
}
3843

44+
/**
45+
* Local private reference to game.
46+
*/
3947
private _game: Game;
4048

49+
/**
50+
* Reference to AudioContext instance.
51+
*/
4152
private _context = null;
53+
/**
54+
* Gain node created from audio context.
55+
*/
4256
private _gainNode;
57+
/**
58+
* Volume of sounds.
59+
* @type {number}
60+
*/
4361
private _volume: number;
4462

63+
/**
64+
* Mute sounds.
65+
*/
4566
public mute() {
4667

4768
this._gainNode.gain.value = 0;
4869

4970
}
5071

72+
/**
73+
* Enable sounds.
74+
*/
5175
public unmute() {
5276

5377
this._gainNode.gain.value = this._volume;
@@ -65,6 +89,12 @@ module Phaser {
6589
return this._volume;
6690
}
6791

92+
/**
93+
* Decode a sound with its assets key.
94+
* @param key Assets key of the sound to be decoded.
95+
* @param callback This will be invoked when finished decoding.
96+
* @param sound Optional, its bufer will be set to decoded data.
97+
*/
6898
public decode(key: string, callback = null, sound?: Sound = null) {
6999

70100
var soundData = this._game.cache.getSound(key);
@@ -90,6 +120,13 @@ module Phaser {
90120

91121
}
92122

123+
/**
124+
* Play a sound with its assets key.
125+
* @param key Assets key of the sound you want to play.
126+
* @param volume Optional, volume of the sound you want to play.
127+
* @param loop Optional, loop when it finished playing? (Default to false)
128+
* @return {Sound=} The playing sound object.
129+
*/
93130
public play(key: string, volume?: number = 1, loop?: bool = false): Sound {
94131

95132
if (this._context === null)

Phaser/TweenManager.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,71 @@
77
* The Game has a single instance of the TweenManager through which all Tween objects are created and updated.
88
* Tweens are hooked into the game clock and pause system, adjusting based on the game state.
99
* TweenManager is based heavily on tween.js by sole (http://soledadpenades.com).
10-
* I converted it to TypeScript, swapped the callbacks for signals and patched a few issues with regard
10+
* I converted it to TypeScript, swapped the callbacks for signals and patched a few issues with regard
1111
* to properties and completion errors. Please see https://github.com/sole/tween.js for a full list of contributors.
1212
*/
1313

1414
module Phaser {
1515

1616
export class TweenManager {
1717

18+
/**
19+
* TweenManager constructor
20+
* @param game A reference to the current Game.
21+
*/
1822
constructor(game: Phaser.Game) {
1923

2024
this._game = game;
2125
this._tweens = [];
2226

2327
}
2428

29+
/**
30+
* Local private reference to Game
31+
*/
2532
private _game: Phaser.Game;
33+
/**
34+
* Local private array which is the container of all tween objects.
35+
*/
2636
private _tweens: Phaser.Tween[];
2737

38+
/**
39+
* Get all the tween objects in an array.
40+
* @return {array=} Array with all tween objects.
41+
*/
2842
public getAll() {
2943

3044
return this._tweens;
3145

3246
}
3347

48+
/**
49+
* Remove all tween objects.
50+
*/
3451
public removeAll() {
3552

3653
this._tweens.length = 0;
3754

3855
}
3956

57+
/**
58+
* Create a tween object for a specific object.
59+
*
60+
* @param object Object you wish the tween will affect.
61+
* @return {Phaser.Tween=} The newly created tween object.
62+
*/
4063
public create(object): Phaser.Tween {
4164

4265
return new Phaser.Tween(object, this._game);
4366

4467
}
4568

69+
/**
70+
* Add an exist tween object to the manager.
71+
*
72+
* @param tween The tween object you want to add.
73+
* @return {Phaser.Tween} The tween object you added to the manager.
74+
*/
4675
public add(tween: Phaser.Tween) {
4776

4877
tween.parent = this._game;
@@ -53,6 +82,11 @@ module Phaser {
5382

5483
}
5584

85+
/**
86+
* Remove a tween from this manager.
87+
*
88+
* @param tween The tween object you want to remove.
89+
*/
5690
public remove(tween: Phaser.Tween) {
5791

5892
var i = this._tweens.indexOf(tween);
@@ -64,6 +98,11 @@ module Phaser {
6498

6599
}
66100

101+
/**
102+
* Update all the tween objects you added to this manager.
103+
*
104+
* @return {boolean} Return false if there's no tween to update, otherwise return true.
105+
*/
67106
public update() {
68107

69108
if (this._tweens.length === 0)

0 commit comments

Comments
 (0)