Skip to content

Commit d846cdb

Browse files
authored
Merge pull request phaserjs#4797 from xSke/docs/path-docs
Improve documentation for Phaser.Curves.Path
2 parents ddbb9b2 + b74c9ae commit d846cdb

1 file changed

Lines changed: 36 additions & 25 deletions

File tree

src/curves/path/Path.js

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,9 @@ var Path = new Class({
624624
},
625625

626626
/**
627-
* [description]
627+
* 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.
628+
*
629+
* When calling this method multiple times, the points are not guaranteed to be equally spaced spatially.
628630
*
629631
* @method Phaser.Curves.Path#getRandomPoint
630632
* @since 3.0.0
@@ -633,7 +635,7 @@ var Path = new Class({
633635
*
634636
* @param {Phaser.Math.Vector2} [out] - `Vector2` instance that should be used for storing the result. If `undefined` a new `Vector2` will be created.
635637
*
636-
* @return {Phaser.Math.Vector2} [description]
638+
* @return {Phaser.Math.Vector2} The modified `out` object, or a new `Vector2` if none was provided.
637639
*/
638640
getRandomPoint: function (out)
639641
{
@@ -643,14 +645,16 @@ var Path = new Class({
643645
},
644646

645647
/**
646-
* Creates a straight Line Curve from the ending point of the Path to the given coordinates.
648+
* Divides this Path into a set of equally spaced points,
649+
*
650+
* The resulting points are equally spaced with respect to the points' position on the path, but not necessarily equally spaced spatially.
647651
*
648652
* @method Phaser.Curves.Path#getSpacedPoints
649653
* @since 3.0.0
650654
*
651-
* @param {integer} [divisions=40] - The X coordinate of the line's ending point, or the line's ending point as a `Vector2`.
655+
* @param {integer} [divisions=40] - The amount of points to divide this Path into.
652656
*
653-
* @return {Phaser.Math.Vector2[]} [description]
657+
* @return {Phaser.Math.Vector2[]} A list of the points this path was subdivided into.
654658
*/
655659
getSpacedPoints: function (divisions)
656660
{
@@ -672,16 +676,16 @@ var Path = new Class({
672676
},
673677

674678
/**
675-
* [description]
679+
* Returns the starting point of the Path.
676680
*
677681
* @method Phaser.Curves.Path#getStartPoint
678682
* @since 3.0.0
679683
*
680684
* @generic {Phaser.Math.Vector2} O - [out,$return]
681685
*
682-
* @param {Phaser.Math.Vector2} [out] - [description]
686+
* @param {Phaser.Math.Vector2} [out] - `Vector2` instance that should be used for storing the result. If `undefined` a new `Vector2` will be created.
683687
*
684-
* @return {Phaser.Math.Vector2} [description]
688+
* @return {Phaser.Math.Vector2} The modified `out` object, or a new Vector2 if none was provided.
685689
*/
686690
getStartPoint: function (out)
687691
{
@@ -691,15 +695,15 @@ var Path = new Class({
691695
},
692696

693697
/**
694-
* Creates a line curve from the previous end point to x/y
698+
* Creates a line curve from the previous end point to x/y.
695699
*
696700
* @method Phaser.Curves.Path#lineTo
697701
* @since 3.0.0
698702
*
699-
* @param {(number|Phaser.Math.Vector2)} x - [description]
700-
* @param {number} [y] - [description]
703+
* @param {(number|Phaser.Math.Vector2)} x - The X coordinate of the line's end point, or a `Vector2` containing the entire end point.
704+
* @param {number} [y] - The Y coordinate of the line's end point, if a number was passed as the X parameter.
701705
*
702-
* @return {Phaser.Curves.Path} [description]
706+
* @return {Phaser.Curves.Path} This Path object.
703707
*/
704708
lineTo: function (x, y)
705709
{
@@ -717,17 +721,15 @@ var Path = new Class({
717721
return this.add(new LineCurve([ end.x, end.y, this._tmpVec2B.x, this._tmpVec2B.y ]));
718722
},
719723

720-
// Creates a spline curve starting at the previous end point, using the given parameters
721-
722724
/**
723-
* [description]
725+
* Creates a spline curve starting at the previous end point, using the given points on the curve.
724726
*
725727
* @method Phaser.Curves.Path#splineTo
726728
* @since 3.0.0
727729
*
728-
* @param {Phaser.Math.Vector2[]} points - [description]
730+
* @param {Phaser.Math.Vector2[]} points - The points the newly created spline curve should consist of.
729731
*
730-
* @return {Phaser.Curves.Path} [description]
732+
* @return {Phaser.Curves.Path} This Path object.
731733
*/
732734
splineTo: function (points)
733735
{
@@ -737,28 +739,37 @@ var Path = new Class({
737739
},
738740

739741
/**
740-
* [description]
742+
* Creates a "gap" in this path from the path's current end point to the given coordinates.
743+
*
744+
* After calling this function, this Path's end point will be equal to the given coordinates
741745
*
742746
* @method Phaser.Curves.Path#moveTo
743747
* @since 3.0.0
744748
*
745-
* @param {number} x - [description]
746-
* @param {number} y - [description]
749+
* @param {(number|Phaser.Math.Vector2)} x - The X coordinate of the position to move the path's end point to, or a `Vector2` containing the entire new end point.
750+
* @param {number} y - The Y coordinate of the position to move the path's end point to, if a number was passed as the X coordinate.
747751
*
748-
* @return {Phaser.Curves.Path} [description]
752+
* @return {Phaser.Curves.Path} This Path object.
749753
*/
750754
moveTo: function (x, y)
751755
{
752-
return this.add(new MovePathTo(x, y));
756+
if (x instanceof Vector2)
757+
{
758+
return this.add(new MovePathTo(x.x, x.y));
759+
}
760+
else
761+
{
762+
return this.add(new MovePathTo(x, y));
763+
}
753764
},
754765

755766
/**
756-
* [description]
767+
* Converts this Path to a JSON object containing the path information and its consitutent curves.
757768
*
758769
* @method Phaser.Curves.Path#toJSON
759770
* @since 3.0.0
760771
*
761-
* @return {Phaser.Types.Curves.JSONPath} [description]
772+
* @return {Phaser.Types.Curves.JSONPath} The JSON object containing this path's data.
762773
*/
763774
toJSON: function ()
764775
{
@@ -792,7 +803,7 @@ var Path = new Class({
792803
},
793804

794805
/**
795-
* [description]
806+
* Disposes of this Path, clearing its internal references to objects so they can be garbage-collected.
796807
*
797808
* @method Phaser.Curves.Path#destroy
798809
* @since 3.0.0

0 commit comments

Comments
 (0)