You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/gameobjects/rope/Rope.js
+52-19Lines changed: 52 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ var Vector2 = require('../../math/Vector2');
37
37
* @param {number} y - The vertical position of this Game Object in the world.
38
38
* @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
39
39
* @param {(string|integer|null)} [frame] - An optional frame from the Texture this Game Object is rendering with.
40
-
* @param {Phaser.Types.Math.Vector2Like[]} [points] - An array containing the vertices data for this Rope. If none is provided a simple quad is created. See `setPoints` to set this post-creation.
40
+
* @param {(integer|Phaser.Types.Math.Vector2Like[])} [points] - An array containing the vertices data for this Rope, or a number that indicates how many segments to split the texture frame into. If none is provided a simple quad is created. See `setPoints` to set this post-creation.
41
41
* @param {number[]} [colors] - An optional array containing the color data for this Rope. You should provide one color value per pair of vertices.
42
42
* @param {number[]} [alphas] - An optional array containing the alpha data for this Rope. You should provide one alpha value per pair of vertices.
43
43
*/
@@ -64,7 +64,7 @@ var Rope = new Class({
64
64
{
65
65
if(points===undefined)
66
66
{
67
-
points=[{x: 0,y: 0}];
67
+
points=2;
68
68
}
69
69
70
70
GameObject.call(this,scene,'Rope');
@@ -175,7 +175,10 @@ var Rope = new Class({
175
175
this.setSizeToFrame();
176
176
this.initPipeline('TextureTintStripPipeline');
177
177
178
-
this.resizeArrays(points.length);
178
+
if(Array.isArray(points))
179
+
{
180
+
this.resizeArrays(points.length);
181
+
}
179
182
180
183
this.setPoints(points,colors,alphas);
181
184
@@ -438,42 +441,79 @@ var Rope = new Class({
438
441
* ]);
439
442
* ```
440
443
*
444
+
* Or, you can provide an integer to do the same thing:
445
+
*
446
+
* ```javascript
447
+
* rope.setPoints(4);
448
+
* ```
449
+
*
450
+
* Which will divide the Rope into 4 equally sized segments based on the frame width.
451
+
*
441
452
* Note that calling this method with a different number of points than the Rope has currently will
442
453
* _reset_ the color and alpha values, unless you provide them as arguments to this method.
443
454
*
444
-
* See also `Rope.split`.
445
-
*
446
455
* @method Phaser.GameObjects.Rope#setPoints
447
456
* @since 3.23.0
448
457
*
449
-
* @param {Phaser.Math.Types.Vector2Like[]} [points] - An array of points to split the Rope into.
458
+
* @param {(integer|Phaser.Types.Math.Vector2Like[])} [points] - An array containing the vertices data for this Rope, or a number that indicates how many segments to split the texture frame into. If none is provided a simple quad is created.
450
459
* @param {(number|number[])} [colors] - Either a single color value, or an array of values.
451
460
* @param {(number|number[])} [alphas] - Either a single alpha value, or an array of values.
0 commit comments