Skip to content

Commit 00ef200

Browse files
pixelpicoseanphotonstorm
authored andcommitted
Finish document for Time, Tween, Animation, AnimationLoader, Frame.
1 parent e88c486 commit 00ef200

5 files changed

Lines changed: 251 additions & 50 deletions

File tree

Phaser/Time.ts

Lines changed: 78 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ module Phaser {
1010

1111
export class Time {
1212

13+
/**
14+
* Time constructor
15+
* Create a new <code>Time</code>.
16+
*
17+
* @param game {Phaser.Game} Current game instance.
18+
*/
1319
constructor(game: Game) {
1420

1521
this._started = Date.now();
@@ -18,32 +24,47 @@ module Phaser {
1824

1925
}
2026

27+
/**
28+
* Local private reference to game.
29+
*/
2130
private _game: Game;
31+
/**
32+
* Time when this object created.
33+
* @param {number}
34+
*/
2235
private _started: number;
2336

24-
37+
/**
38+
* Time scale factor.
39+
* Set it to 0.5 for slow motion, to 2.0 makes game twice faster.
40+
* @type {number}
41+
*/
2542
public timeScale: number = 1.0;
43+
/**
44+
* Elapsed since last frame.
45+
* @type {number}
46+
*/
2647
public elapsed: number = 0;
2748

2849
/**
29-
*
30-
* @property time
31-
* @type Number
32-
*/
50+
* Game time counter.
51+
* @property time
52+
* @type {number}
53+
*/
3354
public time: number = 0;
3455

3556
/**
36-
*
37-
* @property now
38-
* @type Number
39-
*/
57+
* Time of current frame.
58+
* @property now
59+
* @type {number}
60+
*/
4061
public now: number = 0;
4162

4263
/**
43-
*
44-
* @property delta
45-
* @type Number
46-
*/
64+
* Elapsed time since last frame.
65+
* @property delta
66+
* @type {number}
67+
*/
4768
public delta: number = 0;
4869

4970
/**
@@ -57,19 +78,47 @@ module Phaser {
5778

5879
}
5980

81+
/**
82+
* Frames per second.
83+
* @type {number}
84+
*/
6085
public fps: number = 0;
86+
/**
87+
* Minimal fps.
88+
* @type {number}
89+
*/
6190
public fpsMin: number = 1000;
91+
/**
92+
* Maximal fps.
93+
* @type {number}
94+
*/
6295
public fpsMax: number = 0;
96+
/**
97+
* Mininal duration between 2 frames.
98+
* @type {number}
99+
*/
63100
public msMin: number = 1000;
101+
/**
102+
* Maximal duration between 2 frames.
103+
* @type {number}
104+
*/
64105
public msMax: number = 0;
106+
/**
107+
* How many frames in last second.
108+
* @type {number}
109+
*/
65110
public frames: number = 0;
66111

112+
/**
113+
* Time of last second.
114+
* @type {number}
115+
*/
67116
private _timeLastSecond: number = 0;
68117

69118
/**
70-
*
71-
* @method update
72-
*/
119+
* Update clock and calc fps.
120+
* @method update
121+
*/
73122
public update() {
74123

75124
// Can we use performance.now() ?
@@ -102,33 +151,33 @@ module Phaser {
102151
}
103152

104153
/**
105-
*
106-
* @method elapsedSince
107-
* @param {Number} since
108-
* @return {Number}
109-
*/
154+
* How long has passed since given time.
155+
* @method elapsedSince
156+
* @param {number} since The time you want to measure.
157+
* @return {number} Duration between given time and now.
158+
*/
110159
public elapsedSince(since: number): number {
111160

112161
return this.now - since;
113162

114163
}
115164

116165
/**
117-
*
118-
* @method elapsedSecondsSince
119-
* @param {Number} since
120-
* @return {Number}
121-
*/
166+
* How long has passed since give time (in seconds).
167+
* @method elapsedSecondsSince
168+
* @param {number} since The time you want to measure (in seconds).
169+
* @return {number} Duration between given time and now (in seconds).
170+
*/
122171
public elapsedSecondsSince(since: number): number {
123172

124173
return (this.now - since) * 0.001;
125174

126175
}
127176

128177
/**
129-
*
130-
* @method reset
131-
*/
178+
* Set the start time to now.
179+
* @method reset
180+
*/
132181
public reset() {
133182

134183
this._started = this.now;

Phaser/system/Tween.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ module Phaser {
2121

2222
export class Tween {
2323

24+
/**
25+
* Tween constructor
26+
* Create a new <code>Tween</code>.
27+
*
28+
* @param object {object} Target object will be affected by this tween.
29+
* @param game {Phaser.Game} Current game instance.
30+
*/
2431
constructor(object, game:Phaser.Game) {
2532

2633
this._object = object;
@@ -37,24 +44,75 @@ module Phaser {
3744

3845
}
3946

47+
/**
48+
* Local private reference to game.
49+
*/
4050
private _game: Phaser.Game;
51+
/**
52+
* Manager of this tween.
53+
* @type {Phaser.TweenManager}
54+
*/
4155
private _manager: Phaser.TweenManager;
56+
/**
57+
* Reference to the target object.
58+
* @type {object}
59+
*/
4260
private _object = null;
4361
private _pausedTime: number = 0;
4462

63+
/**
64+
* Start values container.
65+
* @type {object}
66+
*/
4567
private _valuesStart = {};
68+
/**
69+
* End values container.
70+
* @type {object}
71+
*/
4672
private _valuesEnd = {};
73+
/**
74+
* How long this tween will perform.
75+
* @type {number}
76+
*/
4777
private _duration = 1000;
4878
private _delayTime = 0;
4979
private _startTime = null;
80+
/**
81+
* Easing function which actually updating this tween.
82+
* @type {function}
83+
*/
5084
private _easingFunction;
5185
private _interpolationFunction;
86+
/**
87+
* Contains chained tweens.
88+
* @type {Tweens[]}
89+
*/
5290
private _chainedTweens = [];
5391

92+
/**
93+
* Signal to be dispatched when this tween start.
94+
* @type {Phaser.Signal}
95+
*/
5496
public onStart: Phaser.Signal;
97+
/**
98+
* Signal to be dispatched when this tween updating.
99+
* @type {Phaser.Signal}
100+
*/
55101
public onUpdate: Phaser.Signal;
102+
/**
103+
* Signal to be dispatched when this tween completed.
104+
* @type {Phaser.Signal}
105+
*/
56106
public onComplete: Phaser.Signal;
57107

108+
/**
109+
* Config the tween result.
110+
* @param properties {object} Propertis you want to tween.
111+
* @param duration {number} Optional, duration of this tween.
112+
* @param ease {any} Easing function.
113+
* @param autoStart {boolean} Whether this tween will start automatically or not.
114+
* @return {Tween} Itself.
115+
*/
58116
public to(properties, duration?: number = 1000, ease?: any = null, autoStart?: bool = false) {
59117

60118
this._duration = duration;
@@ -78,6 +136,9 @@ module Phaser {
78136

79137
}
80138

139+
/**
140+
* Start to tween.
141+
*/
81142
public start() {
82143

83144
if (this._game === null || this._object === null)
@@ -120,6 +181,9 @@ module Phaser {
120181

121182
}
122183

184+
/**
185+
* Stop tweening.
186+
*/
123187
public stop() {
124188

125189
if (this._manager !== null)
@@ -164,6 +228,11 @@ module Phaser {
164228
return this._interpolationFunction;
165229
}
166230

231+
/**
232+
* Add another chained tween, which will start automatically when the one before it completes.
233+
* @param tween {Phaser.Tween} Tween object you want to chain with this.
234+
* @return {Phaser.Tween} Itselfe.
235+
*/
167236
public chain(tween:Phaser.Tween) {
168237

169238
this._chainedTweens.push(tween);
@@ -172,8 +241,16 @@ module Phaser {
172241

173242
}
174243

244+
/**
245+
* Debug value?
246+
*/
175247
public debugValue;
176248

249+
/**
250+
* Update tweening.
251+
* @param time {number} Current time from game clock.
252+
* @return {boolean} Return false if this completed and no need to update, otherwise return true.
253+
*/
177254
public update(time) {
178255

179256
if (this._game.paused == true)

0 commit comments

Comments
 (0)