Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.