-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrope.js
More file actions
24 lines (21 loc) · 822 Bytes
/
Copy pathrope.js
File metadata and controls
24 lines (21 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Rope{
constructor(bodyA, bodyB, offsetX, offsetY){
//these are the offsets of the bodyB where the constraint will connect it to bodyA
this.offsetX = offsetX
this.offsetY = offsetY
var options = {
bodyA: bodyA,
bodyB: bodyB,
pointB: {x: this.offsetX, y: this.offsetY},
}
this.rope = Constraint.create(options);//creates a constraint between bodyA and bodyB
World.add(world, this.rope);//adds this constraint to the world
}
display(){
//some name spacing
var pointA = this.rope.bodyA.position;
var pointB = this.rope.bodyB.position;
//this is a line over the constraint to show the rope
line(pointA.x, pointA.y, pointB.x + this.offsetX, pointB.y + this.offsetY);
}
}