Skip to content

Commit 2560a68

Browse files
committed
update readme and remove redundant plugins
1 parent d727e86 commit 2560a68

8 files changed

Lines changed: 211 additions & 306 deletions

File tree

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
[brm.io/matter-js](http://brm.io/matter-js/)
66

7-
[Demos](#demos) - [Gallery](#gallery) - [Features](#features) - [Install](#install) - [Usage](#usage) - [Examples](#examples) - [Docs](#documentation) - [Wiki](https://github.com/liabru/matter-js/wiki) - [References](#references) - [License](#license)
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)
88

99
[![Build Status](https://travis-ci.org/liabru/matter-js.png?branch=master)](https://travis-ci.org/liabru/matter-js)
1010

@@ -97,6 +97,7 @@ See how others are using matter.js physics
9797
- Constraints
9898
- Gravity
9999
- Sleeping and static bodies
100+
- Plugins
100101
- Rounded corners (chamfering)
101102
- Views (translate, zoom)
102103
- Collision queries (raycasting, region tests)
@@ -129,6 +130,15 @@ Also see the [Rendering](https://github.com/liabru/matter-js/wiki/Rendering) wik
129130
See the [examples](https://github.com/liabru/matter-js/tree/master/examples) directory which contains the source for all [demos](#demos).
130131
There are even more examples on [codepen](http://codepen.io/collection/Fuagy/).
131132

133+
### Plugins
134+
135+
The engine can be extended through plugins, see these resources:
136+
137+
- [Using plugins](https://github.com/liabru/matter-js/wiki/Using-plugins)
138+
- [Creating plugins](https://github.com/liabru/matter-js/wiki/Creating-plugins)
139+
- [List of plugins](https://github.com/liabru/matter-js/wiki/List-of-plugins)
140+
- [matter-plugin-boilerplate](https://github.com/liabru/matter-plugin-boilerplate)
141+
132142
### Documentation
133143

134144
See the [API Documentation](http://brm.io/matter-js/docs/) and the [wiki](https://github.com/liabru/matter-js/wiki)

demo/index.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@
2626
<script src="/demo/lib/matter-tools.demo.js"></script>
2727

2828
<!-- Plugins -->
29-
<script src="../examples/attractorsPlugin.js"></script>
30-
<script src="../examples/gravityPlugin.js"></script>
31-
<script src="../examples/wrapPlugin.js"></script>
29+
<script src="/demo/lib/matter-wrap.js"></script>
3230

3331
<!-- Examples -->
3432
<script src="../examples/airFriction.js"></script>
35-
<script src="../examples/attractors.js"></script>
3633
<script src="../examples/avalanche.js"></script>
3734
<script src="../examples/ballPool.js"></script>
3835
<script src="../examples/bridge.js"></script>

demo/js/Demo.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
init: Example.airFriction,
3535
sourceLink: sourceLinkRoot + '/airFriction.js'
3636
},
37-
{
38-
name: 'Attractors',
39-
id: 'attractors',
40-
init: Example.attractors,
41-
sourceLink: sourceLinkRoot + '/attractors.js'
42-
},
4337
{
4438
name: 'Avalanche',
4539
id: 'avalanche',

demo/lib/matter-wrap.js

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/*!
2+
* matter-wrap 0.1.2 by Liam Brummitt 2017-02-12
3+
* https://github.com/liabru/matter-wrap
4+
* License MIT
5+
*/
6+
(function webpackUniversalModuleDefinition(root, factory) {
7+
if(typeof exports === 'object' && typeof module === 'object')
8+
module.exports = factory(require("Matter"));
9+
else if(typeof define === 'function' && define.amd)
10+
define(["Matter"], factory);
11+
else if(typeof exports === 'object')
12+
exports["MatterWrap"] = factory(require("Matter"));
13+
else
14+
root["MatterWrap"] = factory(root["Matter"]);
15+
})(this, function(__WEBPACK_EXTERNAL_MODULE_0__) {
16+
return /******/ (function(modules) { // webpackBootstrap
17+
/******/ // The module cache
18+
/******/ var installedModules = {};
19+
20+
/******/ // The require function
21+
/******/ function __webpack_require__(moduleId) {
22+
23+
/******/ // Check if module is in cache
24+
/******/ if(installedModules[moduleId])
25+
/******/ return installedModules[moduleId].exports;
26+
27+
/******/ // Create a new module (and put it into the cache)
28+
/******/ var module = installedModules[moduleId] = {
29+
/******/ i: moduleId,
30+
/******/ l: false,
31+
/******/ exports: {}
32+
/******/ };
33+
34+
/******/ // Execute the module function
35+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
36+
37+
/******/ // Flag the module as loaded
38+
/******/ module.l = true;
39+
40+
/******/ // Return the exports of the module
41+
/******/ return module.exports;
42+
/******/ }
43+
44+
45+
/******/ // expose the modules object (__webpack_modules__)
46+
/******/ __webpack_require__.m = modules;
47+
48+
/******/ // expose the module cache
49+
/******/ __webpack_require__.c = installedModules;
50+
51+
/******/ // identity function for calling harmony imports with the correct context
52+
/******/ __webpack_require__.i = function(value) { return value; };
53+
54+
/******/ // define getter function for harmony exports
55+
/******/ __webpack_require__.d = function(exports, name, getter) {
56+
/******/ if(!__webpack_require__.o(exports, name)) {
57+
/******/ Object.defineProperty(exports, name, {
58+
/******/ configurable: false,
59+
/******/ enumerable: true,
60+
/******/ get: getter
61+
/******/ });
62+
/******/ }
63+
/******/ };
64+
65+
/******/ // getDefaultExport function for compatibility with non-harmony modules
66+
/******/ __webpack_require__.n = function(module) {
67+
/******/ var getter = module && module.__esModule ?
68+
/******/ function getDefault() { return module['default']; } :
69+
/******/ function getModuleExports() { return module; };
70+
/******/ __webpack_require__.d(getter, 'a', getter);
71+
/******/ return getter;
72+
/******/ };
73+
74+
/******/ // Object.prototype.hasOwnProperty.call
75+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
76+
77+
/******/ // __webpack_public_path__
78+
/******/ __webpack_require__.p = "/libs";
79+
80+
/******/ // Load entry module and return exports
81+
/******/ return __webpack_require__(__webpack_require__.s = 1);
82+
/******/ })
83+
/************************************************************************/
84+
/******/ ([
85+
/* 0 */
86+
/***/ (function(module, exports) {
87+
88+
module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
89+
90+
/***/ }),
91+
/* 1 */
92+
/***/ (function(module, exports, __webpack_require__) {
93+
94+
"use strict";
95+
96+
97+
var Matter = __webpack_require__(0);
98+
99+
/**
100+
* A coordinate wrapping plugin for matter.js.
101+
* See the readme for usage and examples.
102+
* @module MatterWrap
103+
*/
104+
var MatterWrap = {
105+
// plugin meta
106+
name: 'matter-wrap', // PLUGIN_NAME
107+
version: '0.1.0', // PLUGIN_VERSION
108+
for: 'matter-js@^0.12.0',
109+
110+
// installs the plugin where `base` is `Matter`
111+
// you should not need to call this directly.
112+
install: function install(base) {
113+
base.after('Engine.update', function () {
114+
MatterWrap.Engine.update(this);
115+
});
116+
},
117+
118+
Engine: {
119+
/**
120+
* Updates the engine by wrapping bodies inside `engine.world`.
121+
* This is called automatically by the plugin.
122+
* @function MatterWrap.Engine.update
123+
* @param {Matter.Engine} engine The engine to update.
124+
* @returns {void} No return value.
125+
*/
126+
update: function update(engine) {
127+
var world = engine.world,
128+
bodies = Matter.Composite.allBodies(world);
129+
130+
for (var i = 0; i < bodies.length; i += 1) {
131+
var body = bodies[i];
132+
133+
if (body.plugin.wrap) {
134+
MatterWrap.Body.wrap(body, body.plugin.wrap);
135+
}
136+
}
137+
}
138+
},
139+
140+
Body: {
141+
/**
142+
* Wraps the `body` position such that it always stay within the given bounds.
143+
* Upon crossing a boundary the body will appear on the opposite side of the bounds,
144+
* while maintaining its velocity.
145+
* This is called automatically by the plugin.
146+
* @function MatterAttractors.Body.wrap
147+
* @param {Matter.Body} body The body to wrap.
148+
* @param {Matter.Bounds} bounds The bounds to wrap the body inside.
149+
* @returns {void} No return value.
150+
*/
151+
wrap: function wrap(body, bounds) {
152+
var x = null,
153+
y = null;
154+
155+
if (typeof bounds.min.x !== 'undefined' && typeof bounds.max.x !== 'undefined') {
156+
if (body.bounds.min.x > bounds.max.x) {
157+
x = bounds.min.x - (body.bounds.max.x - body.position.x);
158+
} else if (body.bounds.max.x < bounds.min.x) {
159+
x = bounds.max.x - (body.bounds.min.x - body.position.x);
160+
}
161+
}
162+
163+
if (typeof bounds.min.y !== 'undefined' && typeof bounds.max.y !== 'undefined') {
164+
if (body.bounds.min.y > bounds.max.y) {
165+
y = bounds.min.y - (body.bounds.max.y - body.position.y);
166+
} else if (body.bounds.max.y < bounds.min.y) {
167+
y = bounds.max.y - (body.bounds.min.y - body.position.y);
168+
}
169+
}
170+
171+
if (x !== null || y !== null) {
172+
Matter.Body.setPosition(body, {
173+
x: x || body.position.x,
174+
y: y || body.position.y
175+
});
176+
}
177+
}
178+
}
179+
};
180+
181+
Matter.Plugin.register(MatterWrap);
182+
183+
module.exports = MatterWrap;
184+
185+
/**
186+
* @namespace Matter.Body
187+
* @see http://brm.io/matter-js/docs/classes/Body.html
188+
*/
189+
190+
/**
191+
* This plugin adds a new property `body.plugin.wrap` to instances of `Matter.Body`.
192+
* This is a `Matter.Bounds` instance that specifies the wrapping region.
193+
* @property {Matter.Bounds} body.plugin.wrap
194+
* @memberof Matter.Body
195+
*/
196+
197+
/***/ })
198+
/******/ ]);
199+
});

examples/attractors.js

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)