Skip to content

Commit b7bf5d6

Browse files
committed
added Demo.compound
1 parent 9c139ed commit b7bf5d6

2 files changed

Lines changed: 11 additions & 35 deletions

File tree

demo/dev.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ <h1>Matter.js Demo (Dev. Build)</h1>
3030
<div class="controls-container">
3131
<select id="demo-select">
3232
<option value="mixed">Mixed Shapes</option>
33-
<option value="concave">Concave Shapes</option>
3433
<option value="mixedSolid">Solid Rendering</option>
34+
<option value="compound">Compound Bodies</option>
3535
<option value="newtonsCradle">Newton's Cradle</option>
3636
<option value="wreckingBall">Wrecking Ball</option>
3737
<option value="slingshot">Slingshot Game</option>

demo/js/Demo.js

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -117,52 +117,28 @@
117117
var renderOptions = _engine.render.options;
118118
};
119119

120-
Demo.concave = function() {
120+
Demo.compound = function() {
121121
var _world = _engine.world;
122122

123123
Demo.reset();
124124

125-
var s = 50;
126-
//var vertices = [{ x: 0, y: 0 }, { x: 0, y: 2 * s },
127-
// { x: 1 * s, y: 2 * s }, { x: 1 * s, y: 1 * s },
128-
// { x: 2 * s, y: 1 * s }, { x: 2 * s, y: 0 }];
125+
var partA = Bodies.rectangle(200, 200, 200, 40),
126+
partB = Bodies.rectangle(200, 200, 40, 200);
129127

130-
//var vertices = Matter.Vertices.fromPath('-5 78,70 126,57 195,114 139,191 201,161 136,217 83,151 83,122 -1,82 85');
131-
132-
var partA = Bodies.rectangle(200, 200, 200, 20);
133-
var partB = Bodies.rectangle(200, 200, 20, 200);
134-
var middle = Bodies.rectangle(200, 200, 20, 20);
135-
//var parent = Bodies.rectangle(200, 200, 200, 200);
136-
137-
var vertices = Matter.Vertices.create(partA.vertices.concat(partB.vertices.concat(middle.vertices)), true);
138-
Matter.Vertices.clockwiseSort(vertices);
139-
140-
//debugger;
141-
142-
var hull = Matter.Vertices.hull(vertices);
143-
144-
console.log(vertices);
145-
console.log(hull);
146-
147-
var parent = Body.create({
148-
position: { x: 200, y: 200 },
149-
vertices: hull
128+
var compound = Body.create({
129+
parts: [partA, partB]
150130
});
151131

152-
//debugger;
132+
World.add(_world, compound);
153133

154-
partA.parent = parent;
155-
partB.parent = parent;
156-
157-
parent.parts = [parent, partA, partB];
158-
159-
World.add(_world, parent);
160-
161-
_world.gravity.y = 0;
134+
_world.gravity.y = 1;
162135

163136
var renderOptions = _engine.render.options;
164137
renderOptions.showCollisions = true;
165138
renderOptions.showBounds = true;
139+
renderOptions.showAxes = true;
140+
renderOptions.showPositions = true;
141+
renderOptions.showConvexHulls = true;
166142
};
167143

168144
Demo.slingshot = function() {

0 commit comments

Comments
 (0)