Best way to use custom version of matter.js

I’ve been prototyping a game using matter.js and was thinking of starting to move it over to Phaser 3. I haven’t built anything except fooled around with some of the demos with Phaser. I’m not much of a JS/TS/web guy, so much of this is new. I have, however worked on other platforms and have built games.

Whilst building the initial prototype, I’ve had to modify matter.js. I have no idea if the changes I made will eventually make its way into the code on GitHub.

Assuming it won’t, what’s the best way to manage using a different fork of matter.js with Phaser?

Thanks!

Phaser is bundled with its own copy of Matter.js. Perhaps the cleanest way to customize it is to change the library in Phaser’s source code, located in src/physics/matter-js/lib, then build Phaser yourself. The downside of this is that you’ll have to merge your fork of Matter.js with Phaser’s for every new version of Phaser that gets released.

If you don’t want to do that, another option is to monkey patch (i.e. change at runtime) the library used by Phaser. This is tricky because it’s not directly exposed. You’ll have to either modify src/physics/matter-js/index.js to expose the files in lib, or figure out some way to get an instance of one of the classes you want to change.

Thanks so much for the reply. I’ll try out your variations once I get more used to Phaser. I am currently doing everything locally and linking a local copy of phaser.js as I learn more about it, so I can modify that version directly.

Heh, it turns out one change (ignoreGravity) is already in the phaser version, so that’s one less thing to worry about.