Navigation

April 2019 Phaser Backers Code Bundle inc. Phaser 3D

Published on 3rd April 2019

Greetings everyone! Here's is a brand new Code Bundle just for you lovely backers :)

As with all bundles, download the zip and open it into a folder somewhere in your webroot. Or use the npm script to launch a http server (details are in the readme file). For new backers it's worth mentioning that this bundle includes all previous months too, so you don't need to download them all!

This bundle is a bit special because it includes the new Phaser3D plugin. Yes, you read that right, and no, this isn't a belated April fools joke. Back when I was working on Spine support in Phaser 3, I created a brand new teeny tiny Game Object that had one special purpose. It is called an Extern and what it allows is for Phaser to pass-off full control over the gl context to a 3rd party, which can then do whatever it needs with it, and returns back to Phaser again.

Phaser3D is a plugin that uses a new Extern Game Object and injects Three.js into it. It configures it properly for you, so that three.js can happily write to the current context and then restores itself cleanly when it's finished. Because Externs sit on the display list like any other Game Object, you can layer your game content around a three.js scene. This means you could add 3D backdrops behind your 2D games, or 3D objects over the top of a 2D game, or any combination of.

Of course, you can fully control three.js from Phaser too. This isn't some cut-down hobbled version of it, it's literally the entire library. Every single thing three.js can do, you can do via Phaser3D. There are loads and loads of helper methods to ease your workflow. These cover features like creating all supported forms of geometry, add spot, point or hemisphere lights, enabling shadows and fog, creating cameras, groups and all lots more. I've also included support for GLTF Models. You can, of course, load any other format, but as GLTF is the new standard, I included methods directly for it.

You can preload any textures or models that three.js needs via the Phaser loader, so they can be part of your normal preload sequence, or you can use the three.js loader instead - it's up to you.

Included in the bundle are no less than 34 examples, covering all kinds of different features, from geometry, to cube maps to an example showing how to layer a normal 2D Phaser game over a 3D backdrop. There's even a little demo showing how to use Matter.js bodies for 3D objects. It's a powerful combination and I hope you have fun playing with the demos, checking out the code and seeing what you come up with :)

phaser-backers-examples-apr2019.zip