craftyMatter
Crafty Wrapper for Matter.js physics library
install
Install the required packages:
npm install craftyjs matter-js crafty-matter
temporary fix : Do to working with the edge build version of matter I had to make a couple fixes. So the
recommended matter lib version is on the libs
folder.
Load the script on your HTML file:
And you're ready to go!
Usage
Init matter
Launch Crafty.Matter.Init
passing an options object [optional].
CraftyMatter;
Options suported:
debug: will create a debug body for each entity containing the Matter
component. It will
also highlight the physic world with a light green color.
gravity: by default { x: 0, y: 0 }
size: matter world size. by default { x: Crafty.viewport.width, y: Crafty.viewport.height }
Component
Crafty ;
It will create a Matter rectangle body with the dimensions in the attr object. The matter sub-object allows you to set matter specific config to your entity body.
Objects rotation origin will automatically to center, to fit Matter-js. Changing the origin will give unexpected results.
Circle
Crafty; Crafty ;
If radius
property is no specified. It will use the w
property divided by 2.
Modify matter directly
The matter body reference for an entity with the Matter
component will be the property _body
. Use it to apply matter changes directly.
var entity = Crafty ; MatterBody;
Also the Crafty.Matter
contains a reference to engine
and world
matter components.
MatterWorld;
TODO
- Demo
- Bodies.polygon
- Bodies.trapezoid
- Bodies.fromVertices