Skip to content

Instantly share code, notes, and snippets.

@Joncom
Created July 20, 2015 06:44
Show Gist options
  • Save Joncom/44db1d01a83f995beb2d to your computer and use it in GitHub Desktop.
Save Joncom/44db1d01a83f995beb2d to your computer and use it in GitHub Desktop.
ImpactJS + Box2D: Draw world body vertex positions
ig.system.context.save();
ig.system.context.fillStyle = '#A6E22E';
var radius = 3 * ig.system.scale;
for (var body = ig.world.GetBodyList(); body; body = body.GetNext()) {
for (var fixture = body.GetFixtureList(); fixture; fixture = fixture.GetNext()) {
var shape = fixture.GetShape();
if (shape.GetType() == Box2D.Collision.Shapes.b2Shape.e_polygonShape) {
var poly = shape;
poly.GetVertices().forEach(function(vertex) {
var pos = body.GetWorldPoint(vertex.Copy());
var centerX = (pos.x/Box2D.SCALE) * ig.system.scale;
var centerY = (pos.y/Box2D.SCALE) * ig.system.scale;
ig.system.context.beginPath();
ig.system.context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
ig.system.context.fill();
});
}
}
}
ig.system.context.restore();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment