Published on 27th May 2016
Welcome to Issue 32 of Phaser World
There's a special-length Development Progress section this week, where we show off some of the new features of Arcade Physics 2, including a benchmark you can run.
The cover game this week is the epic Crown of the Gods. The scope of this thing is insane, and it's clearly pushing Phaser to its limits! Maybe it's time to upgrade to an NVIDIA GTX 1080 :)
Until next issue, happy coding. Drop me a line if you've got any news you'd like featured (you can just reply to this email) or grab me on the Phaser Slack channel.
News
Discover Phaser was one of the first Phaser books released, and the author is back with a huge update and lots of new content.
We've also got the Mega Bundle on sale right now. This is $150 worth of Phaser plugins and books for $90. Including Box2D, Particle Storm and Interphase.
Games made with Phaser
Game of the Week
An intricate, competitive, strategy MMO, set in a vast fantasy world.
Ranger Steve: Buffalo Invasion
Staff Pick
A realtime, explosive shoot-em-up. Kill more to get better weapons!
Collect the fruit and veg to prepare for harvest time in this beautiful match 3.
Created for LD35 Sky Panic is a nice cute 'em up with an interesting development post-mortem.
Take to your mechs and fight in this turn-based multiplayer online artillery strategy game.
Phaser Tutorials
A new mini tutorial on handling slopes in Arcade Physics based games.
Understanding Phaser Sprite Animation.
Export FLA library symbols to JS and PNG, ready formatted for Phaser.
A Behavior System plugin for Phaser games.
Create a Breakout game in less than 50 lines of code.
Development Progress
Felipe has been hard at work on Arcade Physics 2 for Lazer. This week has seen stacks of development, including implementations of Arcade Physics simulation (velocity, acceleration, gravity, bounce, etc) and polygon collision solving. Remember this is using the new SAT functions we've created, rather than just the bounding box tests Phaser has.
Here are some gifs (hopefully you can see them animated in the newsletter!). The first showing masses of bodies being emitted, and the second the new collision system in operation:
This new Lazer’s Arcade Physics 2 system exposes a very similar API to Phaser’s Arcade. For example you’ll still be able to affect a body using properties like velocity, acceleration, bounce, drag, friction, mass, etc:
This means that ...
sprite.body.velocity.x = getSomeValue();
... will still be a valid way of setting body properties by hand.
A new thing that that you must have in mind is that when creating a Body you’ll have to also define a Collider type. This is because the collision system uses a SAT (Separating Axis Theorem) based solver. This means that it now handles convex polygon collisions. This is how you can define a new Body in Arcade 2:
var newBody = new Body(130, 20, new RectangleCollider(0, 0, 100, 100));
This will create a body with a position (x:130, y:20) and a rectangle collider of (x: 0, y: 0, width: 100, height: 100).
So what really changed?
Externally Arcade Physics 2 will look very similar to the current API, but internally it had a complete remake. Originally Phaser handles bodies and physics simulation iterating through each body. Something like this:
for (var a = this.children.length; a--; )
this.children[a].preUpdate();
Inside the preUpdate function we have something like this:
this.game.physics.arcade.updateMotion(this);
This is a very straightforward and easy to understand Object-Oriented approach. The problem with this is that it has many performance pitfalls. Just to mention some, multiple branches inside tight loops, hash map look ups through all the member access and polymorphism (which is terrible for JS compiler optimizer).
All the jumping from one function to another, accessing members randomly affect performance greatly, specially on modern CPU. The approach I took for the new physics system is inspired from Data Oriented Design. Basically what I wanted to do is take advantage of data locality and avoid as much as I could cache misses.
So how does the new system look internally? It's more like this:
let SystemPositionX = new Float32Array(MAX_CAPACITY);
let SystemPositionY = new Float32Array(MAX_CAPACITY);
let SystemVelocityX = new Float32Array(MAX_CAPACITY);
let SystemVelocityY = new Float32Array(MAX_CAPACITY);
export function RunSimulationFrame(physicsElapsed) {
for (let index = 0; index < BodyCount; ++index) {
SystemPositionX[index] += SystemVelocityX[index];
SystemPositionY[index] += SystemVelocityY[index];
Here we are taking advantage of Typed Arrays contiguous memory blocks. As we know they have that property this will make accessing the data much faster. There is also the fact that we are not doing any hash map look ups and also avoiding as much as possible branching.
Benchmark Test
Here is a small benchmark which explains a bit the problem and the solution. You are welcome to try it out. The performance of your browser will be recorded.
You can follow the progress of Lazer in the official GitHub repos, where you'll find all the tests above.
Geeky Links
Gameboy Hardware: A fantastically well presented video showing how Memory Mapping worked on the original Gameboy (check out the first video too!)
Super Famicom: The Box Art Collection is a book every geek should have near their coffee table! Beautiful stuff.
and finally this week Javatari is a complete Atari 2600 emulator, with a great interface, coded in JavaScript.
Phaser Releases
The current version of Phaser is 2.4.8 released on May 19th 2016.
Phaser 2.5.0 is now in development. Follow progress on the GitHub dev branch.
Please help support Phaser development on Patreon.
Have some news you'd like published? Email [email protected] or tweet us.
Missed an issue? Check out the Back Issues page.