-
Notifications
You must be signed in to change notification settings - Fork 2k
Getting started
Download the latest release and include the script in your web page e.g.
<script src="matter-0.8.0.js" type="text/javascript"></script>For the latest features try the edge version (master), but it may not be fully stable.
Or install using Bower
install matter-js
Or install using NPM
npm install matter-js
Here is a minimal example to get you started.
// Matter.js module aliases
var Engine = Matter.Engine,
World = Matter.World,
Bodies = Matter.Bodies;
// create a Matter.js engine
var engine = Engine.create(document.body);
// create two boxes and a ground
var boxA = Bodies.rectangle(400, 200, 80, 80);
var boxB = Bodies.rectangle(450, 50, 80, 80);
var ground = Bodies.rectangle(400, 610, 810, 60, { isStatic: true });
// add all of the bodies to the world
World.add(engine.world, [boxA, boxB, ground]);
// run the engine
Engine.run(engine);Include the above script into a page that has Matter.js installed and then open the page in your browser.
Hopefully you will see two rectangle bodies fall and then hit each other as they land on the ground. If you don't, check the browser console to see if there are any errors.
Check out the demo page for more examples and then refer to Demo.js to see how they work. Some of the demos are also available on codepen, where you can easily experiment with them.
See the latest Matter.js API Docs for detailed information on the API. If you're using the edge version (master) then see the API Docs (master).