Skip to content

Instantly share code, notes, and snippets.

@calderaro
Created July 19, 2019 17:43
Show Gist options
  • Save calderaro/9073cea18bbc9eeb3bea890dd39e49e4 to your computer and use it in GitHub Desktop.
Save calderaro/9073cea18bbc9eeb3bea890dd39e49e4 to your computer and use it in GitHub Desktop.
Matterjs Notes 1
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/matter.js"></script>
</head>
<body>
<script>
// module aliases
const Engine = Matter.Engine;
const Render = Matter.Render;
const World = Matter.World;
const Bodies = Matter.Bodies;
// create an engine
const engine = Engine.create();
// create a renderer
const render = Render.create({
element: document.body,
engine: engine
});
// create two boxes and a ground
const boxA = Bodies.rectangle(400, 200, 80, 80);
const boxB = Bodies.rectangle(450, 50, 80, 80);
const boxC = Bodies.rectangle(410, -10, 80, 80);
const ground = Bodies.rectangle(400, 610, 810, 60, { isStatic: true });
// add all of the bodies to the world
World.add(engine.world, [boxA, boxB, boxC, ground]);
// run the engine
Engine.run(engine);
// run the renderer
Render.run(render);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment