Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dxu/matter-collision-events
A Matter.js plugin for adding per-body collision events and event handlers.
https://github.com/dxu/matter-collision-events
javascript matter physics-engine
Last synced: about 1 month ago
JSON representation
A Matter.js plugin for adding per-body collision events and event handlers.
- Host: GitHub
- URL: https://github.com/dxu/matter-collision-events
- Owner: dxu
- License: mit
- Created: 2017-02-08T05:46:59.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-04-26T10:35:06.000Z (over 4 years ago)
- Last Synced: 2024-11-14T22:36:51.157Z (about 2 months ago)
- Topics: javascript, matter, physics-engine
- Language: JavaScript
- Homepage:
- Size: 67.4 KB
- Stars: 31
- Watchers: 5
- Forks: 12
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# matter-collision-events
matter-collision-events is a [Matter.js](https://github.com/liabru/matter-js) plugin that adds per-body collision events.
## Installing
`npm install matter-collision-events`
## Usage
Refer to [the official guide on using plugins](https://github.com/liabru/matter-js/wiki/Using-plugins) for step-by-step instructions. `matter-collision-events` can be included in the browser or imported via modules.
You can call `Matter.use('matter-collision-events')` to install the plugin itself for usage.
This plugin triggers three new events on Matter.Body:
1. `onCollide`
2. `onCollideEnd`
3. `onCollideActive`These events correspond to the Matter.js events `collisionStart`, `collisionActive`, and `collisionEnd`, respectively. You can listen to these events via [`Matter.Events`](http://brm.io/matter-js/docs/classes/Events.html#method_on).
This plugin also extends Matter.Body with three convenience functions:
1. `Matter.Body.onCollide(callback)`
2. `Matter.Body.onCollideEnd(callback)`
3. `Matter.Body.onCollideActive(callback)`You can register event callbacks by providing a function of type `( pair: `[`Matter.Pair`](http://brm.io/matter-js/docs/classes/Pair.html)`) => void`:
Example usage can be found under the `docs` folder, which contains [a basic example of its usage](/docs/examples/basic.js).
## Demo
[View the demo here.](https://dxu.github.io/matter-collision-events)
## License
MIT