Phaser学习笔记

introudce

Phaser is an open source HTML5 game framework created by Photon Storm. It's designed to create games that will run on desktop and mobile web browsers. A lot of focus was given to performance inside of mobile web browsers, a growing and important area of web gaming. If the device is capable then it uses WebGL for rendering, but otherwise it seamlessly reverts to Canvas. In this article, I'll cover resources for learning Phaser, as well as showing what it can do and some of the thinking that went into its design.

Yet Another HTML5 Game Framework?!

It's fair to say that it feels as if a new HTML5 game framework is released every week, such is the proliferation of them. So why should you even consider Phaser among the huge choice out there? I like to think that the reason is something to do with the legacy of the team involved in building it.

We at Photon Storm dedicated ourselves to developing nothing but HTML5 games several years ago, back when there really wasn't a great deal of framework choice, and you could count the number of HTML5 game devs in single digits. Entering the space so early, and coming from Flash, we were instantly feeling the need to build tools that we were used to in AS3.

We had been great fans of Flixel and had enjoyed success both with our own games and with our Flixel Power Tools. There was a real buzz seeing other devs use them to help get their games released, and this was something that we wished to duplicate in HTML5.

What we weren't prepared for, however, was just how fast the HTML5 landscape was changing. Even today, I have a slide in my presentations that I show at conferences saying "Be prepared to unlearn what you know every six months", and I believe this still remains true. Browser vendors are iterating and improving at a phenomenal rate right now. It takes only a matter of weeks for new features to bubble through to the public, and if you're saddled with a game framework that is maintained during someone's spare time or is on a slow release cycle, then it doesn't take long before things are very outdated.

Another sign of this change was in the types of client work we were being commissioned to build. As a company we only do two things: build HTML5 games, and build Phaser. We've built HTML5 games for some of the biggest entertainment brands in the world, and that has given us a keen insight into the sorts of requirements they demand. The biggest area we were being asked to work on was games running inside the mobile browser; so many HTML5 frameworks are focused on the desktop, where performance is abundant and connections fast and stable, and ignore the mobile browser side of life. Yet that is where we still see the client demand is strongest. So it was vital that Phaser could be used to build our client games, regardless of platform.

Since the release of Phaser 1.0, updates have been regular and comprehensive, with many new features and fixes in place quickly. We work on a turnaround of approximately one month from dev to master—you can view a complete changelog on GitHub. Interestingly, we're now seeing a demand for games running inside of a WebView, so we will ensure that Phaser operates well in this environment going into 2014.

As well as keeping Phaser up to date, it was also crucially important to us that we built something that was really easy to use. And you will see this reflected across the whole framework. This stems from our experience with the Flixel Power Tools, and beyond that when I used to work for The Game Creators helping to define the shape of their game languages. I guess it has always been part of me that I wanted to make game development as easy as possible for developers, a trend I will continue as Phaser evolves.

I apologise in advance of any of the following (or above!) sounds a bit 'marketing'. Phaser is a free product, we make no money from you using it, and if I enthuse about it, it is only because I'm passionate about what I've created. So please bear with me!