Navigation

Phaser v3.61 Beta 4 is now available

Published on 27th October 2023

I'm happy to announce that Phaser v3.61 Beta 4 is now available.

Grab it from GitHub: https://github.com/photonstorm/phaser/releases/tag/v3.61.0-beta.4 or from npm under the 'beta' tag. There are new dist files, a new ESM module build, new TypeScript defs, and for those who may find it useful, there's a new phaser.json file within the 'types' folder. This is a complete JSDoc dump of the whole library in JSDoc JSON format, which could be really handy depending on your requirements.

This release fixes an annoying issue that slipped through in Beta 3 regarding texture memory. Never deploy on Friday the 13th, I guess :)

It also includes a really handy new feature that I'm sure lots of you can take advantage of. Which is the ability to set an Arcade Physics body to be under 'direct control'. You do this by calling a new method:

Here, we've made a regular Arcade Physics Image, but we have called the new 'setDirectControl' method. Previously, the way to move a body is to give it velocity or acceleration. These forces act upon the body every frame, propelling it in the direction you requested. When two bodies collide, they exchange these forces in order to resolve the collision.

That works for lots of cases, but it makes it hard to do things where you want a body to follow an explicit path, or tween it, or track the mouse pointer. Previously, directly modifying the x/y position of the Body (or, more commonly, its parent Game Object) would cause it to have no velocity, and therefore, collisions would behave strangely, assuming they triggered at all.

Now, if you set the Body to be under direct control, it will calculate its velocity based on its change of position in each frame. This means when it collides with other objects, static or not, it will resolve their collision properly because the direct-controlled Body now has actual velocity. It sounds almost inconsequential, but it allows you to be a lot more flexible with your games now without having to revert to using Matter Physics.

Here are a few examples demonstrating this feature in action:

Click here to run this example

Here, you've got a sprite (our wonderful little cloud master) following the mouse pointer. All we're doing is setting its position to the pointer x/y values, yet it's correctly colliding with all of the falling bouncing coins.

Click here to run this example

In this example, we've got an Arcade Sprite following a complex path. We do this by getting a point from the path and just setting it as the sprites' position. As it moves around the path, it still collides with all of the physics bubbles bouncing around.

Click here to run this example

In this example, I'm using the new Direct Control feature to move the 3 platforms around the Scene, which you can run and jump on (use cursors to control, up to jump). The platforms are being moved with regular tweens, which are just tweening their positions.

There are lots of other applications for this feature - such as patrolling enemies following fixed paths across a map. Or simple actions such as crushing blocks or spikes moving up and down that you need to dash under quickly. This was previously possible by using careful math for your velocity, but it's now significantly simpler to set up and more accurate.

If you get a chance, please test this new feature out and let me know if you encounter any issues. Obviously, it's still using Arcade Physics, so the normal limitations of that system still apply, but I hope it makes your development life easier.

Future Thoughts

There's a lot going on at Phaser HQ right now, and while I can't yet give any more details, there are some huge changes on the horizon both for me personally and for Phaser as a whole. I hope to be able to announce more about this in December, but if things go according to plan, 2024 is going to be extremely exciting indeed! And if you're a Phaser community member, perhaps looking for a new role next year, start brushing up your CV and portfolio :)