https://github.com/liabru/matter-wrap
a coordinate wrapping plugin for matter-js
https://github.com/liabru/matter-wrap
matter-js plugin wrap
Last synced: over 1 year ago
JSON representation
a coordinate wrapping plugin for matter-js
- Host: GitHub
- URL: https://github.com/liabru/matter-wrap
- Owner: liabru
- License: mit
- Created: 2017-02-12T15:50:07.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-04T23:06:40.000Z (almost 9 years ago)
- Last Synced: 2025-03-09T13:35:56.815Z (over 1 year ago)
- Topics: matter-js, plugin, wrap
- Language: JavaScript
- Size: 5 MB
- Stars: 34
- Watchers: 2
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# matter-wrap
> A coordinate wrapping plugin for [matter.js](https://github.com/liabru/matter-js/)
[](https://travis-ci.org/liabru/matter-wrap)
This plugin allows you to automatically wrap the position of bodies and composites such that they always stay within the given bounds. Upon crossing a boundary the body will appear on the opposite side of the bounds, while maintaining its velocity.
An example of this effect can be seen in the classic
[Asteroids](https://www.youtube.com/watch?v=WYSupJ5r2zo) and [Pacman](https://youtu.be/3-C7lHLFLU8?t=63) games.
## Demo
See the [demo](http://liabru.github.io/matter-wrap).
[](http://liabru.github.io/matter-wrap)
## Install
Get the [matter-wrap.js](build/matter-wrap.js) file directly or get it via npm:
npm install matter-wrap
### Dependencies
- [matter.js](https://github.com/liabru/matter-js/)
## Usage
```js
Matter.use('matter-wrap');
// or
Matter.use(MatterWrap);
```
See [Using Plugins](https://github.com/liabru/matter-js/wiki/Using-plugins#using-plugins) for more information.
An example of a body that wraps between the bounds (0, 0) and (1024, 1024).
For wrapping composites set `composite.plugin.wrap` as below.
```js
var body = Matter.Bodies.circle(0, 0, 10, {
plugin: {
wrap: {
min: {
x: 0,
y: 0
},
max: {
x: 1024,
y: 1024
}
}
}
);
```
## Examples
Check out the [examples](docs/examples).
## Documentation
See the [API docs](API.md).