Skip to content

Commit a853b30

Browse files
authored
Merge pull request phaserjs#4940 from samme/docs/misc-3
Docs for Curve, Path, ScenePlugin, BaseSoundManager
2 parents 5e027f7 + 974ffd9 commit a853b30

4 files changed

Lines changed: 84 additions & 48 deletions

File tree

src/curves/Curve.js

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var Vector2 = require('../math/Vector2');
2020
* @constructor
2121
* @since 3.0.0
2222
*
23-
* @param {string} type - [description]
23+
* @param {string} type - The curve type.
2424
*/
2525
var Curve = new Class({
2626

@@ -78,7 +78,7 @@ var Curve = new Class({
7878
this.needsUpdate = true;
7979

8080
/**
81-
* [description]
81+
* For a curve on a Path, `false` means the Path will ignore this curve.
8282
*
8383
* @name Phaser.Curves.Curve#active
8484
* @type {boolean}
@@ -131,7 +131,7 @@ var Curve = new Class({
131131
// So you can chain graphics calls
132132
return graphics.strokePoints(this.getPoints(pointsTotal));
133133
},
134-
134+
135135
/**
136136
* Returns a Rectangle where the position and dimensions match the bounds of this Curve.
137137
*
@@ -187,7 +187,7 @@ var Curve = new Class({
187187
},
188188

189189
/**
190-
* [description]
190+
* Get a point at the end of the curve.
191191
*
192192
* @method Phaser.Curves.Curve#getEndPoint
193193
* @since 3.0.0
@@ -209,7 +209,7 @@ var Curve = new Class({
209209
* @method Phaser.Curves.Curve#getLength
210210
* @since 3.0.0
211211
*
212-
* @return {number} [description]
212+
* @return {number} The total length of the curve.
213213
*/
214214
getLength: function ()
215215
{
@@ -220,14 +220,22 @@ var Curve = new Class({
220220

221221

222222
/**
223-
* Get list of cumulative segment lengths
223+
* Get a list of cumulative segment lengths.
224+
*
225+
* These lengths are
226+
*
227+
* - [0] 0
228+
* - [1] The first segment
229+
* - [2] The first and second segment
230+
* - ...
231+
* - [divisions] All segments
224232
*
225233
* @method Phaser.Curves.Curve#getLengths
226234
* @since 3.0.0
227235
*
228-
* @param {integer} [divisions] - [description]
236+
* @param {integer} [divisions] - The number of divisions or segments.
229237
*
230-
* @return {number[]} [description]
238+
* @return {number[]} An array of cumulative lengths.
231239
*/
232240
getLengths: function (divisions)
233241
{
@@ -268,17 +276,17 @@ var Curve = new Class({
268276
// - u [0 .. 1]
269277

270278
/**
271-
* [description]
279+
* Get a point at a relative position on the curve, by arc length.
272280
*
273281
* @method Phaser.Curves.Curve#getPointAt
274282
* @since 3.0.0
275283
*
276284
* @generic {Phaser.Math.Vector2} O - [out,$return]
277285
*
278-
* @param {number} u - [description]
279-
* @param {Phaser.Math.Vector2} [out] - [description]
286+
* @param {number} u - The relative position, [0..1].
287+
* @param {Phaser.Math.Vector2} [out] - A point to store the result in.
280288
*
281-
* @return {Phaser.Math.Vector2} [description]
289+
* @return {Phaser.Math.Vector2} The point.
282290
*/
283291
getPointAt: function (u, out)
284292
{
@@ -290,13 +298,23 @@ var Curve = new Class({
290298
// Get sequence of points using getPoint( t )
291299

292300
/**
293-
* [description]
301+
* Get a sequence of evenly spaced points from the curve.
302+
*
303+
* You can pass `divisions`, `stepRate`, or neither.
304+
*
305+
* The number of divisions will be
306+
*
307+
* 1. `divisions`, if `divisions` > 0; or
308+
* 2. `this.getLength / stepRate`, if `stepRate` > 0; or
309+
* 3. `this.defaultDivisions`
310+
*
311+
* `1 + divisions` points will be returned.
294312
*
295313
* @method Phaser.Curves.Curve#getPoints
296314
* @since 3.0.0
297315
*
298-
* @param {integer} divisions - The number of evenly spaced points from the curve to return. If falsy, step param will be used to calculate the number of points.
299-
* @param {number} step - Step between points. Used to calculate the number of points to return when divisions is falsy. Ignored if divisions is positive.
316+
* @param {integer} [divisions] - The number of divisions to make.
317+
* @param {number} [stepRate] - The curve distance between points, implying `divisions`.
300318
* @param {(array|Phaser.Math.Vector2[])} [out] - An optional array to store the points in.
301319
*
302320
* @return {(array|Phaser.Math.Vector2[])} An array of Points from the curve.
@@ -327,16 +345,16 @@ var Curve = new Class({
327345
},
328346

329347
/**
330-
* [description]
348+
* Get a random point from the curve.
331349
*
332350
* @method Phaser.Curves.Curve#getRandomPoint
333351
* @since 3.0.0
334352
*
335353
* @generic {Phaser.Math.Vector2} O - [out,$return]
336354
*
337-
* @param {Phaser.Math.Vector2} [out] - [description]
355+
* @param {Phaser.Math.Vector2} [out] - A point object to store the result in.
338356
*
339-
* @return {Phaser.Math.Vector2} [description]
357+
* @return {Phaser.Math.Vector2} The point.
340358
*/
341359
getRandomPoint: function (out)
342360
{
@@ -348,16 +366,18 @@ var Curve = new Class({
348366
// Get sequence of points using getPointAt( u )
349367

350368
/**
351-
* [description]
369+
* Get a sequence of equally spaced points (by arc distance) from the curve.
370+
*
371+
* `1 + divisions` points will be returned.
352372
*
353373
* @method Phaser.Curves.Curve#getSpacedPoints
354374
* @since 3.0.0
355375
*
356-
* @param {integer} [divisions] - The number of evenly spaced points from the curve to return. If falsy, step param will be used to calculate the number of points.
357-
* @param {number} [step] - Step between points. Used to calculate the number of points to return when divisions is falsy. Ignored if divisions is positive.
376+
* @param {integer} [divisions=this.defaultDivisions] - The number of divisions to make.
377+
* @param {number} [stepRate] - Step between points. Used to calculate the number of points to return when divisions is falsy. Ignored if divisions is positive.
358378
* @param {(array|Phaser.Math.Vector2[])} [out] - An optional array to store the points in.
359379
*
360-
* @return {Phaser.Math.Vector2[]} [description]
380+
* @return {Phaser.Math.Vector2[]} An array of points.
361381
*/
362382
getSpacedPoints: function (divisions, stepRate, out)
363383
{
@@ -387,16 +407,16 @@ var Curve = new Class({
387407
},
388408

389409
/**
390-
* [description]
410+
* Get a point at the start of the curve.
391411
*
392412
* @method Phaser.Curves.Curve#getStartPoint
393413
* @since 3.0.0
394414
*
395415
* @generic {Phaser.Math.Vector2} O - [out,$return]
396416
*
397-
* @param {Phaser.Math.Vector2} [out] - [description]
417+
* @param {Phaser.Math.Vector2} [out] - A point to store the result in.
398418
*
399-
* @return {Phaser.Math.Vector2} [description]
419+
* @return {Phaser.Math.Vector2} The point.
400420
*/
401421
getStartPoint: function (out)
402422
{
@@ -406,7 +426,7 @@ var Curve = new Class({
406426
},
407427

408428
/**
409-
* Returns a unit vector tangent at t
429+
* Get a unit vector tangent at a relative position on the curve.
410430
* In case any sub curve does not implement its tangent derivation,
411431
* 2 points a small delta apart will be used to find its gradient
412432
* which seems to give a reasonable approximation
@@ -416,8 +436,8 @@ var Curve = new Class({
416436
*
417437
* @generic {Phaser.Math.Vector2} O - [out,$return]
418438
*
419-
* @param {number} t - [description]
420-
* @param {Phaser.Math.Vector2} [out] - [description]
439+
* @param {number} t - The relative position on the curve, [0..1].
440+
* @param {Phaser.Math.Vector2} [out] - A vector to store the result in.
421441
*
422442
* @return {Phaser.Math.Vector2} Vector approximating the tangent line at the point t (delta +/- 0.0001)
423443
*/
@@ -448,17 +468,17 @@ var Curve = new Class({
448468
},
449469

450470
/**
451-
* [description]
471+
* Get a unit vector tangent at a relative position on the curve, by arc length.
452472
*
453473
* @method Phaser.Curves.Curve#getTangentAt
454474
* @since 3.0.0
455475
*
456476
* @generic {Phaser.Math.Vector2} O - [out,$return]
457477
*
458-
* @param {number} u - [description]
459-
* @param {Phaser.Math.Vector2} [out] - [description]
478+
* @param {number} u - The relative position on the curve, [0..1].
479+
* @param {Phaser.Math.Vector2} [out] - A vector to store the result in.
460480
*
461-
* @return {Phaser.Math.Vector2} [description]
481+
* @return {Phaser.Math.Vector2} The tangent vector.
462482
*/
463483
getTangentAt: function (u, out)
464484
{
@@ -573,10 +593,12 @@ var Curve = new Class({
573593
},
574594

575595
/**
576-
* [description]
596+
* Calculate and cache the arc lengths.
577597
*
578598
* @method Phaser.Curves.Curve#updateArcLengths
579599
* @since 3.0.0
600+
*
601+
* @see Phaser.Curves.Curve#getLengths()
580602
*/
581603
updateArcLengths: function ()
582604
{

src/curves/path/Path.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,14 +569,12 @@ var Path = new Class({
569569
},
570570

571571
/**
572-
* Returns the defined starting point of the Path.
573-
*
574-
* This is not necessarily equal to the starting point of the first Curve if it differs from {@link startPoint}.
572+
* Get a sequence of points on the path.
575573
*
576574
* @method Phaser.Curves.Path#getPoints
577575
* @since 3.0.0
578576
*
579-
* @param {integer} [divisions=12] - The number of points to divide the path in to.
577+
* @param {integer} [divisions=12] - The number of divisions per resolution per curve.
580578
*
581579
* @return {Phaser.Math.Vector2[]} An array of Vector2 objects that containing the points along the Path.
582580
*/
@@ -626,7 +624,7 @@ var Path = new Class({
626624

627625
/**
628626
* Returns a randomly chosen point anywhere on the path. This follows the same rules as `getPoint` in that it may return a point on any Curve inside this path.
629-
*
627+
*
630628
* When calling this method multiple times, the points are not guaranteed to be equally spaced spatially.
631629
*
632630
* @method Phaser.Curves.Path#getRandomPoint
@@ -647,7 +645,7 @@ var Path = new Class({
647645

648646
/**
649647
* Divides this Path into a set of equally spaced points,
650-
*
648+
*
651649
* The resulting points are equally spaced with respect to the points' position on the path, but not necessarily equally spaced spatially.
652650
*
653651
* @method Phaser.Curves.Path#getSpacedPoints
@@ -741,7 +739,7 @@ var Path = new Class({
741739

742740
/**
743741
* Creates a "gap" in this path from the path's current end point to the given coordinates.
744-
*
742+
*
745743
* After calling this function, this Path's end point will be equal to the given coordinates
746744
*
747745
* @method Phaser.Curves.Path#moveTo

src/scene/ScenePlugin.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ var ScenePlugin = new Class({
188188
/**
189189
* Shutdown this Scene and run the given one.
190190
*
191+
* This will happen at the next Scene Manager update, not immediately.
192+
*
191193
* @method Phaser.Scenes.ScenePlugin#start
192194
* @since 3.0.0
193195
*
@@ -209,6 +211,8 @@ var ScenePlugin = new Class({
209211
/**
210212
* Restarts this Scene.
211213
*
214+
* This will happen at the next Scene Manager update, not immediately.
215+
*
212216
* @method Phaser.Scenes.ScenePlugin#restart
213217
* @since 3.4.0
214218
*
@@ -444,6 +448,8 @@ var ScenePlugin = new Class({
444448
/**
445449
* Launch the given Scene and run it in parallel with this one.
446450
*
451+
* This will happen at the next Scene Manager update, not immediately.
452+
*
447453
* @method Phaser.Scenes.ScenePlugin#launch
448454
* @since 3.0.0
449455
*
@@ -465,6 +471,8 @@ var ScenePlugin = new Class({
465471
/**
466472
* Runs the given Scene, but does not change the state of this Scene.
467473
*
474+
* This will happen at the next Scene Manager update, not immediately.
475+
*
468476
* If the given Scene is paused, it will resume it. If sleeping, it will wake it.
469477
* If not running at all, it will be started.
470478
*
@@ -492,6 +500,8 @@ var ScenePlugin = new Class({
492500
/**
493501
* Pause the Scene - this stops the update step from happening but it still renders.
494502
*
503+
* This will happen at the next Scene Manager update, not immediately.
504+
*
495505
* @method Phaser.Scenes.ScenePlugin#pause
496506
* @since 3.0.0
497507
*
@@ -512,6 +522,8 @@ var ScenePlugin = new Class({
512522
/**
513523
* Resume the Scene - starts the update loop again.
514524
*
525+
* This will happen at the next Scene Manager update, not immediately.
526+
*
515527
* @method Phaser.Scenes.ScenePlugin#resume
516528
* @since 3.0.0
517529
*
@@ -532,6 +544,8 @@ var ScenePlugin = new Class({
532544
/**
533545
* Makes the Scene sleep (no update, no render) but doesn't shutdown.
534546
*
547+
* This will happen at the next Scene Manager update, not immediately.
548+
*
535549
* @method Phaser.Scenes.ScenePlugin#sleep
536550
* @since 3.0.0
537551
*
@@ -552,6 +566,8 @@ var ScenePlugin = new Class({
552566
/**
553567
* Makes the Scene wake-up (starts update and render)
554568
*
569+
* This will happen at the next Scene Manager update, not immediately.
570+
*
555571
* @method Phaser.Scenes.ScenePlugin#wake
556572
* @since 3.0.0
557573
*
@@ -571,11 +587,8 @@ var ScenePlugin = new Class({
571587

572588
/**
573589
* Makes this Scene sleep then starts the Scene given.
574-
*
575-
* No checks are made to see if an instance of the given Scene is already running.
576-
* Because Scenes in Phaser are non-exclusive, you are allowed to run multiple
577-
* instances of them _at the same time_. This means, calling this function
578-
* may launch another instance of the requested Scene if it's already running.
590+
*
591+
* This will happen at the next Scene Manager update, not immediately.
579592
*
580593
* @method Phaser.Scenes.ScenePlugin#switch
581594
* @since 3.0.0
@@ -597,6 +610,8 @@ var ScenePlugin = new Class({
597610
/**
598611
* Shutdown the Scene, clearing display list, timers, etc.
599612
*
613+
* This happens at the next Scene Manager update, not immediately.
614+
*
600615
* @method Phaser.Scenes.ScenePlugin#stop
601616
* @since 3.0.0
602617
*
@@ -814,7 +829,7 @@ var ScenePlugin = new Class({
814829
* The Scene is removed from the local scenes array, it's key is cleared from the keys
815830
* cache and Scene.Systems.destroy is then called on it.
816831
*
817-
* If the SceneManager is processing the Scenes when this method is called it wil
832+
* If the SceneManager is processing the Scenes when this method is called it will
818833
* queue the operation for the next update sequence.
819834
*
820835
* @method Phaser.Scenes.ScenePlugin#remove

src/sound/BaseSoundManager.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ var BaseSoundManager = new Class({
227227
},
228228

229229
/**
230-
* Enables playing sound on the fly without the need to keep a reference to it.
231-
* Sound will auto destroy once its playback ends.
230+
* Adds a new sound to the sound manager and plays it.
231+
* The sound will be automatically removed (destroyed) once playback ends.
232+
* This lets you play a new sound on the fly without the need to keep a reference to it.
232233
*
233234
* @method Phaser.Sound.BaseSoundManager#play
234235
* @listens Phaser.Sound.Events#COMPLETE

0 commit comments

Comments
 (0)