Skip to content

Commit 0d84860

Browse files
committed
Update Matter.World to render compound bodies
1 parent 0e10091 commit 0d84860

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

src/physics/matter-js/World.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -373,25 +373,30 @@ var World = new Class({
373373

374374
for (var i = 0; i < bodies.length; i++)
375375
{
376-
var body = bodies[i];
377-
378-
if (!body.render.visible)
376+
if (!bodies[i].render.visible)
379377
{
380-
continue;
378+
return;
381379
}
382380

383-
var vertices = body.vertices;
381+
// Handle drawing both single bodies and compound bodies. If compound, draw both the
382+
// convex hull (first part) and the rest of the bodies.
383+
for (var j = 0; j < bodies[i].parts.length; j++)
384+
{
385+
var body = bodies[i].parts[j];
384386

385-
graphics.moveTo(vertices[0].x, vertices[0].y);
387+
var vertices = body.vertices;
386388

387-
for (var j = 1; j < vertices.length; j++)
388-
{
389-
graphics.lineTo(vertices[j].x, vertices[j].y);
390-
}
389+
graphics.moveTo(vertices[0].x, vertices[0].y);
390+
391+
for (var k = 1; k < vertices.length; k++)
392+
{
393+
graphics.lineTo(vertices[k].x, vertices[k].y);
394+
}
391395

392-
graphics.lineTo(vertices[0].x, vertices[0].y);
396+
graphics.lineTo(vertices[0].x, vertices[0].y);
393397

394-
graphics.strokePath();
398+
graphics.strokePath();
399+
}
395400
}
396401
},
397402

0 commit comments

Comments
 (0)