# loaf-matter

> A library to help you use matter.js

Latest version **0.0.10** (published 2018-12-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install loaf-matter
pnpm add loaf-matter
yarn add loaf-matter
bun add loaf-matter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.10 |
| Published | 2018-12-05 |
| First published | 2018-12-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 1 |
| Unpacked size | 14.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | falsy |
| Maintainers | falsy.me |
| Keywords | matterjs, 2D, physics |

## Links

- npm: https://www.npmjs.com/package/loaf-matter
- Repository: https://github.com/loafjs/loaf-matter
- Homepage: https://lab.falsy.me
- Issues: https://github.com/loafjs/loaf-matter/issues
- npm.io page: https://npm.io/package/loaf-matter

## Dependencies (1)

- [matter-js](https://npm.io/package/matter-js.md) ^0.14.2

## Recent versions

- 0.0.10 (latest) — 2018-12-05
- 0.0.9 — 2018-12-05
- 0.0.8 — 2018-12-05
- 0.0.7 — 2018-12-04
- 0.0.6 — 2018-12-04
- 0.0.5 — 2018-12-04
- 0.0.4 — 2018-12-04
- 0.0.3 — 2018-12-04
- 0.0.2 — 2018-12-03
- 0.0.1 — 2018-12-03

## README

# Loaf Matter [![npm](https://img.shields.io/npm/v/loaf-matter.svg)](https://www.npmjs.com/package/loaf-matter) [![npm](https://img.shields.io/npm/dm/loaf-matter.svg)](https://www.npmjs.com/package/loaf-matter)
A library to help you use [matter.js](http://brm.io/matter-js/). this is based on using one world and one engine.  
I currently use Webpack, Babel, React. you do not need to use React, but you should use Webpack and Babel.

## Notice
This is unstable because it is an early version.

## Required
* [Matter.js](http://brm.io/matter-js/)
* [Webpack.js](https://webpack.js.org/)
* [Babel.js](https://babeljs.io/)

## Install
```
npm install --save matter-js
```
```
npm install --save loaf-matter
```

## Example
You can go to the 'example' directory, install the example source, and check the run.
```
cd ./example
```
```
npm install
```
```
npm start
```

## Basic function
You can use the basic function of matter.js as is.  
```js
import Matter from 'matter-js';

Matter.Bodies.circle(100, 100, 20); 
```
Below is the same as above.
```js
import LM from 'loaf-matter';

LM.Bodies.circle(100, 100, 20); 
```

## Shortening function
You can abbreviate the method using additional predefined methods.  
```js
import Matter from 'matter-js';

const Bodies = Matter.Bodies;
const World = Matter.World;
const Render = Matter.Render;
const Engine = Matter.Engine;

const engine = Engine.create();
const render = Render.create({
  element: document.body,
  engine: engine,
  options: {
    width: 500,
    height: 500
  }
});

const circle = Bodies.circle(100, 100, 20);
World.add(engine.world, circle);

Engine.run(engine);
Render.run(render);
```
It can be used as follows.
```js
import LM from 'loaf-matter';

LM.setEngine();
LM.setRender({
  element: document.body,
  engine: LM.engine,
  option: {
    width: 500,
    height: 500
  }
});

const circle = LM.addObjet('circle', [100, 100, 20]);
circle.show();

LM.runEngine();
LM.runRender();
```

## Shape class definition
By default, you can inherit the defined classes.
```js
// ./ChildObjet.js
import LM, { Objet } from 'loaf-matter';

class ChildObjet extends Objet {

  constructor(...props) {
    super(...props);
  }

  move(x, y) {
    this.setVelocity(x, y);
  }
}

export default ChildObjet
```
```js
import ChildFigure from './ChildFigure';

const newObjet = new ChildFigure('rectangle', [100, 100, 30, 30]);
newObjet.show();
```
Here, `this.setVelocity()` functions as `Matter.Body.setVelocity(body, vertices)`.  
link. http://brm.io/matter-js/docs/classes/Body.html#method_setVelocity

## Add Methods
### 1. addObjet()  
Create an Objet that inherits a few methods.  
For example, you can add an Objet to World with the included show method.  
```js
import LM from 'loaf-matter';

const circle = LM.addObjet('circle', [100, 100, 20]);
circle.show();
```

### 2. ignoreGravity()  
Let the individual Objet ignore gravity.  
For example, 'circle' falls under the influence of gravity, 'ignoreGravitycircle' is not affected by its gravity and will remain in place.
```js
import LM from 'loaf-matter';

LM.setEngine();
LM.setGravity(0, 0.3);

...

const circle = LM.addObjet('circle', [200, 200, 20]);
circle.show();

const ignoreGravitycircle = LM.addObjet('circle', [100, 100, 20]);
ignoreGravitycircle.show();
ignoreGravitycircle.ignoreGravity();
```

---
_Source: https://npm.io/package/loaf-matter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
