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.
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.
If you are contributing to this library, here is how to get started:
npm install --global yarn
.yarn
to install and link dependencies.yarn run XYZ
to run a script from that workspace.