Skip to content

Commit 72c3b55

Browse files
committed
Testing vertical Rope support
1 parent 4c9c505 commit 72c3b55

1 file changed

Lines changed: 43 additions & 12 deletions

File tree

src/gameobjects/rope/Rope.js

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ var Rope = new Class({
170170
*/
171171
this._perp = new Vector2();
172172

173+
this.debug = null;
174+
175+
// this.horizontal = true;
176+
this.horizontal = false;
177+
173178
this.setTexture(texture, frame);
174179
this.setPosition(x, y);
175180
this.setSizeToFrame();
@@ -475,13 +480,28 @@ var Rope = new Class({
475480
segments = 2;
476481
}
477482

478-
var frameSegment = this.frame.width / (segments - 1);
479-
480483
points = [];
481484

482-
for (var s = 0; s < segments; s++)
485+
var s;
486+
var frameSegment;
487+
488+
if (this.horizontal)
483489
{
484-
points.push({ x: s * frameSegment, y: 0 });
490+
frameSegment = this.frame.width / (segments - 1);
491+
492+
for (s = 0; s < segments; s++)
493+
{
494+
points.push({ x: s * frameSegment, y: 0 });
495+
}
496+
}
497+
else
498+
{
499+
frameSegment = this.frame.height / (segments - 1);
500+
501+
for (s = 0; s < segments; s++)
502+
{
503+
points.push({ x: 0, y: s * frameSegment });
504+
}
485505
}
486506
}
487507

@@ -518,10 +538,20 @@ var Rope = new Class({
518538
{
519539
var index = i * 4;
520540

521-
currentUVs[index] = u0 + (i * part);
522-
currentUVs[index + 1] = v0;
523-
currentUVs[index + 2] = u0 + (i * part);
524-
currentUVs[index + 3] = v1;
541+
if (this.horizontal)
542+
{
543+
currentUVs[index] = u0 + (i * part);
544+
currentUVs[index + 1] = v0;
545+
currentUVs[index + 2] = u0 + (i * part);
546+
currentUVs[index + 3] = v1;
547+
}
548+
else
549+
{
550+
currentUVs[index] = u1;
551+
currentUVs[index + 1] = v0 + (i * part);
552+
currentUVs[index + 2] = u0;
553+
currentUVs[index + 3] = v0 + (i * part);
554+
}
525555
}
526556

527557
this.points = points;
@@ -603,8 +633,10 @@ var Rope = new Class({
603633
return;
604634
}
605635

606-
var lastPoint = points[0];
607636
var nextPoint;
637+
var lastPoint = points[0];
638+
639+
var frameSize = (this.horizontal) ? this.frame.halfHeight : this.frame.halfWidth;
608640

609641
for (var i = 0; i < total; i++)
610642
{
@@ -624,13 +656,12 @@ var Rope = new Class({
624656
perp.y = -(nextPoint.x - lastPoint.x);
625657

626658
var perpLength = perp.length();
627-
var num = this.frame.halfHeight;
628659

629660
perp.x /= perpLength;
630661
perp.y /= perpLength;
631662

632-
perp.x *= num;
633-
perp.y *= num;
663+
perp.x *= frameSize;
664+
perp.y *= frameSize;
634665

635666
vertices[index] = point.x + perp.x;
636667
vertices[index + 1] = point.y + perp.y;

0 commit comments

Comments
 (0)