Matter TypeScript Definitions overhauled

Published on 14th January 2020

https://www.dropbox.com/temp_thumb_from_token/s/nmduffqlbg86gaa?preserve_transparency=False&size=1200x1200&size_mode=4

Hi all,

If the video above doesn't play, click here to watch it.

I've been working hard this week trying to get Phaser 3.22 released. One of the final obstacles in the way were the Matter Physics TypeScript definitions. While we've had the defs included in the Phaser repo for a while now, they weren't very accurate, and more annoyingly, they didn't link with the Phaser defs properly - so if you created a Body using a Phaser factory, you lost all context awareness of the Body from TypeScript.

This was massively frustrating. So I've spent the past two days fixing it, which effectively meant redoing the Matter defs by hand, mostly from scratch. It was worth the effort though! As you can hopefully see from the embedded video, they now work beautifully from TypeScript. You get proper Body objects back, with all the properties that entails, can pass them around, etc and get all the same benefits for Composites and Constraints, too.

It was an interesting challenge, because in the Matter library there isn't actually a single class to be found. Bodies are not classes, you don't instantiate them. The Body module actually contains a bunch of static functions, one of which is 'create' and all that does is return a Body shaped object. So, it took a good while to redo the defs to handle this properly. Honestly, I'm glad it's all over now :)

I'll do some more testing but that was the last thing holding me back from publishing 3.22, so fingers crossed it can come out very soon now. If you'd like to give the new defs a try you can grab them from the Phaser repo.

https://www.dropbox.com/temp_thumb_from_token/s/nmduffqlbg86gaa?preserve_transparency=False&size=1200x1200&size_mode=4

Hi all,

If the video above doesn't play, click here to watch it.

I've been working hard this week trying to get Phaser 3.22 released. One of the final obstacles in the way were the Matter Physics TypeScript definitions. While we've had the defs included in the Phaser repo for a while now, they weren't very accurate, and more annoyingly, they didn't link with the Phaser defs properly - so if you created a Body using a Phaser factory, you lost all context awareness of the Body from TypeScript.

This was massively frustrating. So I've spent the past two days fixing it, which effectively meant redoing the Matter defs by hand, mostly from scratch. It was worth the effort though! As you can hopefully see from the embedded video, they now work beautifully from TypeScript. You get proper Body objects back, with all the properties that entails, can pass them around, etc and get all the same benefits for Composites and Constraints, too.

It was an interesting challenge, because in the Matter library there isn't actually a single class to be found. Bodies are not classes, you don't instantiate them. The Body module actually contains a bunch of static functions, one of which is 'create' and all that does is return a Body shaped object. So, it took a good while to redo the defs to handle this properly. Honestly, I'm glad it's all over now :)

I'll do some more testing but that was the last thing holding me back from publishing 3.22, so fingers crossed it can come out very soon now. If you'd like to give the new defs a try you can grab them from the Phaser repo.