|
12345678910111213141516171819202122232425262728293031323334 |
- // module aliases
- var Engine = Matter.Engine,
- Render = Matter.Render,
- Runner = Matter.Runner,
- Bodies = Matter.Bodies,
- Composite = Matter.Composite;
-
- // create an engine
- var engine = Engine.create({
- enableSleeping: true,
- });
-
- // create a renderer
- var render = Render.create({
- element: document.body,
- engine: engine
- });
-
- // create two boxes and a ground
- var ground = Bodies.rectangle(400, 500, 700, 50, { isStatic: true });
- var boxA = Bodies.rectangle(401, 240, 40, 20);
- var boxB = Bodies.rectangle(415, 470, 40, 20, { isStatic: true });
-
- // add all of the bodies to the world
- Composite.add(engine.world, [boxA, boxB, ground]);
-
- // run the renderer
- Render.run(render);
-
- // create runner
- var runner = Runner.create();
-
- // run the engine
- Runner.run(runner, engine);
|