All Projects → mikewesthad → phaser-matter-collision-plugin

mikewesthad / phaser-matter-collision-plugin

Licence: MIT License
A plugin for making it easier to manage collisions with Phaser 3 + Matter.js

Programming Languages

CSS
56736 projects
javascript
184084 projects - #8 most used programming language
typescript
32286 projects
Handlebars
879 projects
PLSQL
303 projects
HTML
75241 projects

Phaser Matter Collision Plugin 💥

A plugin for making it easier to manage collisions with the Phaser game engine and the Matter.js physics engine.

Matter is one of the cool physics engine choices you have in Phaser 3. Phaser has a thin wrapper over Matter's API, so you need to dig into Matter's native collision event system if you want to detect and respond to collisions. That system just gives you a dump of all the pairs of bodies that collided in a tick of the engine. This plugin wraps up that collision logic in a more useful way:

const player = this.matter.add.sprite(0, 0, "player");
const trapDoor = this.matter.add.sprite(200, 0, "door");

this.matterCollision.addOnCollideStart({
  objectA: player,
  objectB: trapDoor,
  callback: () => console.log("Player touched door!")
});

Or in a slightly more complicated example:

See interactive versions of that example on CodeSandbox in JavaScript or TypeScript.

If you are reading this on Github or NPM, check out the full HTML documentation here.

Info

This repository uses yarn workspaces to keep the plugin source code together with some example JavaScript and TypeScript projects. See the individual workspaces for more info on each:

  • workspaces/plugin
  • workspaces/javascript-example
  • workspaces/typescript-example
  • workspaces/javascript-no-module-example

If you are looking for the plugin readme, you can find it here.

Development

If you are contributing to this library, here is how to get started:

  • Install Node.
  • npm install --global yarn.
  • Open the root folder of this repository and run yarn to install and link dependencies.
  • Head to the workspace you plan to work on and use yarn run XYZ to run a script from that workspace.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].