Get started with matter-js CDN

MIT licensed

Matter-js is a 2D physics engine for JS games and simulations.

Tags:
  • javascript
  • canvas
  • html5
  • physics
  • physics engine
  • game engine
  • rigid body physics

Stable version

Copied!

How to start using matter-js CDN


// Import Matter.js library
const Engine = Matter.Engine,
      World = Matter.World,
      Bodies = Matter.Bodies,
      Box = Matter.Box,
      Vector = Matter.Vector;

// Create an engine
const engine = Engine.create();

// Create a world and add the engine
const world = World.add(engine.world);

// Create a ground
const ground = Bodies.rectangle(400, 600, 800, 20, { isStatic: true });
World.add(world, ground);

// Create a box
const box = Box.create({
  x: 200,
  y: 200,
  width: 50,
  height: 50,
  mass: 1
});

// Add the box to the world
World.add(world, box);

// Apply a force to the box
Engine.applyForceAtPoint(engine.world, box.position, new Vector(0.01, 0.01));

// Run the engine
Engine.run(engine);
Copied!
Copied!

All versions