1 | <img alt="Matter.js" src="https://brm.io/matter-js/img/matter-js.svg" width="300">
|
2 |
|
3 | > *Matter.js* is a JavaScript 2D rigid body physics engine for the web
|
4 |
|
5 | [brm.io/matter-js](https://brm.io/matter-js/)
|
6 |
|
7 | [Demos](#demos) ・ [Gallery](#gallery) ・ [Features](#features) ・ [Plugins](#plugins) ・ [Install](#install) ・ [Usage](#usage) ・ [Examples](#examples) ・ [Docs](#documentation) ・ [Wiki](https://github.com/liabru/matter-js/wiki) ・ [References](#references) ・ [License](#license)
|
8 |
|
9 | ### Demos
|
10 |
|
11 | <table>
|
12 | <tr>
|
13 | <td>
|
14 | <ul>
|
15 | <li><a href="https://brm.io/matter-js/demo/#mixed">Mixed Shapes</a></li>
|
16 | <li><a href="https://brm.io/matter-js/demo/#mixedSolid">Solid Shapes</a></li>
|
17 | <li><a href="https://brm.io/matter-js/demo/#svg">Concave SVG Paths</a></li>
|
18 | <li><a href="https://brm.io/matter-js/demo/#terrain">Concave Terrain</a></li>
|
19 | <li><a href="https://brm.io/matter-js/demo/#concave">Concave Bodies</a></li>
|
20 | <li><a href="https://brm.io/matter-js/demo/#compound">Compound Bodies</a></li>
|
21 | <li><a href="https://brm.io/matter-js/demo/#newtonsCradle">Newton's Cradle</a></li>
|
22 | <li><a href="https://brm.io/matter-js/demo/#wreckingBall">Wrecking Ball</a></li>
|
23 | <li><a href="https://brm.io/matter-js/demo/#slingshot">Slingshot Game</a></li>
|
24 | <li><a href="https://brm.io/matter-js/demo/#rounded">Rounded Corners</a></li>
|
25 | <li><a href="https://brm.io/matter-js/demo/#views">Views</a></li>
|
26 | <li><a href="https://brm.io/matter-js/demo/#timescale">Time Scaling</a></li>
|
27 | <li><a href="https://brm.io/matter-js/demo/#manipulation">Body Manipulation</a></li>
|
28 | <li><a href="https://brm.io/matter-js/demo/#compositeManipulation">Composite Manipulation</a></li>
|
29 | </ul>
|
30 | </td>
|
31 | <td>
|
32 | <ul>
|
33 | <li><a href="https://brm.io/matter-js/demo/#raycasting">Raycasting</a></li>
|
34 | <li><a href="https://brm.io/matter-js/demo/#sprites">Sprites</a></li>
|
35 | <li><a href="https://brm.io/matter-js/demo/#pyramid">Pyramid</a></li>
|
36 | <li><a href="https://brm.io/matter-js/demo/#car">Car</a></li>
|
37 | <li><a href="https://brm.io/matter-js/demo/#catapult">Catapult</a></li>
|
38 | <li><a href="https://brm.io/matter-js/demo/#gravity">Reverse Gravity</a></li>
|
39 | <li><a href="https://brm.io/matter-js/demo/#bridge">Bridge</a></li>
|
40 | <li><a href="https://brm.io/matter-js/demo/#avalanche">Avalanche</a></li>
|
41 | <li><a href="https://brm.io/matter-js/demo/#softBody">Basic Soft Bodies</a></li>
|
42 | <li><a href="https://brm.io/matter-js/demo/#cloth">Cloth</a></li>
|
43 | <li><a href="https://brm.io/matter-js/demo/#events">Events</a></li>
|
44 | <li><a href="https://brm.io/matter-js/demo/#collisionFiltering">Collision Filtering</a></li>
|
45 | <li><a href="https://brm.io/matter-js/demo/#chains">Chains</a></li>
|
46 | <li><a href="https://brm.io/matter-js/demo/#ballPool">Ball Pool</a></li>
|
47 | </ul>
|
48 | </td>
|
49 | <td>
|
50 | <ul>
|
51 | <li><a href="https://brm.io/matter-js/demo/#stack">Stack</a></li>
|
52 | <li><a href="https://brm.io/matter-js/demo/#circleStack">Circle Stack</a></li>
|
53 | <li><a href="https://brm.io/matter-js/demo/#compoundStack">Compound Stack</a></li>
|
54 | <li><a href="https://brm.io/matter-js/demo/#restitution">Restitution</a></li>
|
55 | <li><a href="https://brm.io/matter-js/demo/#friction">Friction</a></li>
|
56 | <li><a href="https://brm.io/matter-js/demo/#airFriction">Air Friction</a></li>
|
57 | <li><a href="https://brm.io/matter-js/demo/#staticFriction">Static Friction</a></li>
|
58 | <li><a href="https://brm.io/matter-js/demo/#sleeping">Sleeping</a></li>
|
59 | <li><a href="https://brm.io/matter-js/demo/#beachBalls">Beach Balls</a></li>
|
60 | <li><a href="https://brm.io/matter-js/demo/#stress">Stress 1</a></li>
|
61 | <li><a href="https://brm.io/matter-js/demo/#stress2">Stress 2</a></li>
|
62 | <li><a href="https://brm.io/matter-js/demo/#sensors">Sensors</a></li>
|
63 | </ul>
|
64 | <br>
|
65 | </td>
|
66 | </tr>
|
67 | </table>
|
68 |
|
69 | ### Gallery
|
70 |
|
71 | See how others are using matter.js physics
|
72 |
|
73 | - [Patrick Heng](https://patrickheng.com/) by Patrick Heng
|
74 | - [USELESS](https://useless.london/) by Nice and Serious
|
75 | - [Secret 7](https://secret-7.com/) by Goodness
|
76 | - [New Company](https://www.new.company/) by New Company
|
77 | - [Game of The Year](https://gameoftheyear.withgoogle.com/) by Google
|
78 | - [Pablo The Flamingo](https://pablotheflamingo.com/) by Nathan Gordon
|
79 | - [Les métamorphoses de Mr. Kalia](https://lab212.org/oeuvres/2:art/18/Les-metamorphoses-de-Mr-Kalia) by Lab212
|
80 | - [Phaser](https://phaser.io/) by Photon Storm
|
81 | - [Sorry I Have No Filter](https://sorryihavenofilter.com/pages/about/) by Jessica Walsh
|
82 | - [Fuse](https://fuse.blog/) by Fuse
|
83 | - [Glyphfinder](https://www.glyphfinder.com/) by überdosis
|
84 | - [Isolation](https://isolation.is/postcards/my-week) by sabato studio
|
85 | - [more...](https://github.com/liabru/matter-js/wiki/Gallery)
|
86 |
|
87 | ### Features
|
88 |
|
89 | - Rigid bodies
|
90 | - Compound bodies
|
91 | - Composite bodies
|
92 | - Concave and convex hulls
|
93 | - Physical properties (mass, area, density etc.)
|
94 | - Restitution (elastic and inelastic collisions)
|
95 | - Collisions (broad-phase, mid-phase and narrow-phase)
|
96 | - Stable stacking and resting
|
97 | - Conservation of momentum
|
98 | - Friction and resistance
|
99 | - Events
|
100 | - Constraints
|
101 | - Gravity
|
102 | - Sleeping and static bodies
|
103 | - Plugins
|
104 | - Rounded corners (chamfering)
|
105 | - Views (translate, zoom)
|
106 | - Collision queries (raycasting, region tests)
|
107 | - Time scaling (slow-mo, speed-up)
|
108 | - Canvas renderer (supports vectors and textures)
|
109 | - [MatterTools](https://github.com/liabru/matter-tools) for creating, testing and debugging worlds
|
110 | - World state serialisation (requires [resurrect.js](https://github.com/skeeto/resurrect-js))
|
111 | - Cross-browser and Node.js support (Chrome, Firefox, Safari, IE8+)
|
112 | - Mobile-compatible (touch, responsive)
|
113 | - An original JavaScript physics implementation (not a port)
|
114 |
|
115 | ### Install
|
116 |
|
117 | You can install using package managers [npm](https://www.npmjs.org/package/matter-js) and [Yarn](https://yarnpkg.com/) using:
|
118 |
|
119 | npm install matter-js
|
120 |
|
121 | Alternatively you can download a [stable release](https://github.com/liabru/matter-js/tags) or try the latest experimental [alpha build](https://github.com/liabru/matter-js/tree/master/build) (master) and include the script in your web page:
|
122 |
|
123 | <script src="matter.js" type="text/javascript"></script>
|
124 |
|
125 | ### Performance with other tools (e.g. Webpack, Vue etc.)
|
126 |
|
127 | Bundlers and frameworks may reduce real-time performance when using their default configs, especially in development modes.
|
128 |
|
129 | When using [Webpack](https://webpack.js.org/), the default sourcemap config can have a large impact, for a solution see [issue](https://github.com/liabru/matter-js/issues/1001).
|
130 |
|
131 | When using [Vue.js](https://vuejs.org/), watchers can have a large impact, for a solution see [issue](https://github.com/liabru/matter-js/issues/1001#issuecomment-998911435).
|
132 |
|
133 | ### Usage
|
134 |
|
135 | Visit the [Getting started](https://github.com/liabru/matter-js/wiki/Getting-started) wiki page for a minimal usage example which should work in both browsers and Node.js.
|
136 | Also see the [Running](https://github.com/liabru/matter-js/wiki/Running) and [Rendering](https://github.com/liabru/matter-js/wiki/Rendering) wiki pages, which show how to use your own game and rendering loops.
|
137 |
|
138 | ### Tutorials
|
139 |
|
140 | See the list of [tutorials](https://github.com/liabru/matter-js/wiki/Tutorials).
|
141 |
|
142 | ### Examples
|
143 |
|
144 | See the [examples](https://github.com/liabru/matter-js/tree/master/examples) directory which contains the source for all [demos](#demos).
|
145 | There are even more examples on [codepen](https://codepen.io/collection/Fuagy/).
|
146 |
|
147 | ### Plugins
|
148 |
|
149 | The engine can be extended through plugins, see these resources:
|
150 |
|
151 | - [Using plugins](https://github.com/liabru/matter-js/wiki/Using-plugins)
|
152 | - [Creating plugins](https://github.com/liabru/matter-js/wiki/Creating-plugins)
|
153 | - [List of plugins](https://github.com/liabru/matter-js/wiki/List-of-plugins)
|
154 | - [matter-plugin-boilerplate](https://github.com/liabru/matter-plugin-boilerplate)
|
155 |
|
156 | ### Documentation
|
157 |
|
158 | See the [API Documentation](https://brm.io/matter-js/docs/) and the [wiki](https://github.com/liabru/matter-js/wiki)
|
159 |
|
160 | ### Building and Contributing
|
161 |
|
162 | To build you must first install [node.js](https://nodejs.org/), then run
|
163 |
|
164 | npm install
|
165 |
|
166 | This will install the required build dependencies, then run
|
167 |
|
168 | npm run dev
|
169 |
|
170 | to spawn a development server. For information on contributing see [CONTRIBUTING.md](https://github.com/liabru/matter-js/blob/master/CONTRIBUTING.md).
|
171 |
|
172 | ### Changelog
|
173 |
|
174 | To see what's new or changed in the latest version, see the [changelog](https://github.com/liabru/matter-js/blob/master/CHANGELOG.md).
|
175 |
|
176 | ### References
|
177 |
|
178 | See the wiki page on [References](https://github.com/liabru/matter-js/wiki/References).
|
179 |
|
180 | ### License
|
181 |
|
182 | Matter.js is licensed under [The MIT License (MIT)](https://opensource.org/licenses/MIT)
|
183 | Copyright (c) 2014 Liam Brummitt
|
184 |
|
185 | This license is also supplied with the release and source code.
|
186 | As stated in the license, absolutely no warranty is provided.
|