Skip to content

Instantly share code, notes, and snippets.

@lonekorean
Created June 10, 2018 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lonekorean/58a93e3818971209bd64974e98c84bb9 to your computer and use it in GitHub Desktop.
Save lonekorean/58a93e3818971209bd64974e98c84bb9 to your computer and use it in GitHub Desktop.
Loop to create bodies
this.bodies = [];
let totalBodies = Math.round(viewportWidth * viewportHeight / this.options.pixelsPerBody);
for (let i = 0; i <= totalBodies; i++) {
let body = this.createBody(viewportWidth, viewportHeight);
this.bodies.push(body);
}
Matter.World.add(this.engine.world, this.bodies);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment