Using Flash in mobile game development now?
Back in november when Adobe released Flash 11 + AIR 3 I didn’t pay too much attention to it. I have to admit I was too busy to look at it closely (we were pretty focused on “Simplz: Zoo” and other things), but now while moving into new projects I decided to begin a little research on this. I got an intern lately so it was a great opportunity to have someone really focused in reviewing the technology.
Flash technology has been flying around for the last few months. Since the official release of Flash 11 + AIR 3, Adobe did show his cards to actually play a main role in the video games industry as a middleware provider. Even big actors like Epic Games (UDK) orUnity Technologies (Unity 3) have added to the cause. But even though, it’s difficult to realize that we may be using Flash technology as an standard basis in the future. CPU & GPU (mostly the latter) performance has always been the bottleneck on every game development. The more content you present on screen, the worse the performance and Flash has never played well on that field. So what happened with Flash 11? Did Adobe improve things in there?
On a first sight, nobody can ignore that Flash has been installed in almost every computer out there. This means that if you create a game in Flash, “theoretically” everybody will be able to play it. As I said, performance has never been a WIN on Flash, however Adobe claims that Flash 11 definitively supports hardware accelerated rendering (which represents ~90% of the CPU effort of any Flash-based game/web), meaning that things should have improved hugely…
In 2008, when we started the company, Flash wasn’t an option because of the performance. Not even other “better” considered options (like Unity) were up to the task. Either low-mid range PC CPUs or high-end mobile CPUs (ARMv6-based architectures) were actually too “slow”. And what it’s more important, Flash player didn’t run on iPhone (and it hasn’t made it so far). Because of all that plus other technical constraints, we knew C++ was our only choice. It has worked reasonably well for the last 4 years and neither portability (PC + Mac + iOS + Android) nor performance have “never” been compromised. We managed ourselves to build our own engine which worked pretty well until the projects started to grow more and more, the number of devices (considering both iOS and Android) we had to support increased too, and finally we realized we were going to have just one person 100% dedicated to engine+tools development, which we couldn’t afford. Remember? We’re still a small company!
Far from being more comfortable developing in suites/engines such as Unity or Adobe Flash, what you really get is a solid software support across platforms from both the company in charge and the active developer community. If, in addition to that you note that your source code will be considerably smaller, easier to comprehend and easier to fix, then we can forget all the rest. In the end, we just want to develop a game once, ignore the portability issues as much as possible and deploy it everywhere (web browsers, iOS, Android, smart-TVs and future platforms) while having fun Even though, it is clear that if you want to create the next state-of-the-art game at 60 FPS, forget about all those commodities and go back to C/C++ against low-level based libraries such as OpenGL, and this applies not only for mobiles devices but for high-end PCs and consoles as well.
That said, let’s now focus on Flash technology more seriously . I won’t enter into many technical details (this is not supposed to be a tutorial), but I will highlight what I think is important from a developer/programmer point of view. Also, I would like to say I’ll be focusing in 2D rendering exclusively, since I’m not interested in 3D at all right now.
First off, the last version of Flash is 11.1 and the last version of AIR is 3.2, now supporting full-hardware accelerated graphics upon OpenGL ES 2.0, including both vertex and pixel shaders. Of course, this is still ways behind DX11 or OpenGL 3.0 (shader model 5.0), but if you aren’t going to create the last AAA title for next-gen consoles, you shouldn’t worry about . Also, when we say “Flash 11″ in the context of mobile devices, we shall ignore the Flash Player at all. Adobe itself declared that they were finally stopping Flash Player development for handheld devices. So…how the hell a game done in Flash can now be executed on iOS or Android? And this question brings us to the second part of the equation, who is called AIR. This basically acts as a “plugging” for Flash that is in charge of generating a native application instead of the regular “.swf” for the Flash Player. It can generate both “.ipa” (iOS) and “.apk” (Android) application bundles. But you should know that those are not real native applications; in fact, if you compare performance between 2 apps (let’s say identical), one programmed in Action Script 3.0 (Flash) and the other in pure C++, the latter is going to be always faster.
Okay, so the deployment side of things it’s been solved by Adobe, at last . Even those interested in full 3D graphics should know that AIR 3.2 is ready for the task as well, though still in beta. Now let’s focus on Flash technology when it comes to game development in self. I’m going to quickly pass throughout all the technical layers (graphics, input, audio, physics and network) in order to understand the whole picture.
First thing we realized was that apparently, nothing changed compared to previous versions of Flash. Both vectorial and bitmap based data can be used, along with the common movie clips every Flash designer is familiarized with. But we just wanted a way to draw sprites fast (just as we do with our own engine in C++ and OpenGL), and we saw there was a class to do that, called “Stage” (there’s also a 3D version of the class, named “Stage3D”). Adobe ensures that all you put through the Stage will be sent almost directly to the GPU, which is great news . However, as the technology stands upon OpenGL ES 2.0, it means you don’t have the typical “fixed function pipeline”, so it requires you to write almost everything from the scratch using shaders O_o. But…is there any point in writing your own graphics engine for Flash? (I guess not)
As you can see, the first contact with the graphics layer wasn’t good for sure! For some kind of games with very simple mechanics Flash tools may be more than enough, nonetheless you normally need full freedom to control the transitions of dialog & menus, the animation of your characters, the spacial transformations of your screen elements such us particles or any sort of special effect, customized blending effects and so on…
Events & Input
Operative System events and touch-based input is easily handled by Flash & AIR. With just a few lines of Action Script you have everything working, from single taps to complicate gestures using multiple fingers.
It is pretty easy to playback sounds and music. Sounds must be in WAV-PCM uncompressed format while soundtrack in MP3 compressed format. Those who are used to play OGG files may need to study other options…
By default, there’s no physics engine/library in Flash 11. Hopefully we have some alternatives for both 2D and 3D. For 2D specifically we got Box2D which is pretty well known by most developers out there.
Action Script core libraries are ready to deal with online communication issues such as sending data to a server script, downloading data from a server, working with binary or XML socket connections, TCP/UDP packets, etc. But this isn’t really important for us, since we all know that the most difficult part in any online/multiplayer game is the server side. Using FMS (Flash Media Server) is always a possibility, but it looks like there’s other and better options as for example SmartFoxServer. These kind of services abstract you from the server side and provide high performance plus scalable architecture that you don’t need to worry about.
In general, the context is pretty good although we cannot ignore the lack of a decent/already-built graphics engine. Luckily though, there are several options we can consider. In our humbled opinion, the following couple of options are the only ones to consider at the moment (2D specific):
Starling: It is a pretty solid company-driven open-source engine. The API is very well structured and easy to understand, plus the documentation actually rocks. It is updated frequently and enjoys from a lot of community supporting it on a daily basis (dedicated forums, books, video tutorials, etc). As a proof of reliability, Rovio Entertainment just built one of its last projects with this engine. Actually, this is the reason why the game will not see the light in Windows Phone (not yet supported by Flash 11 & AIR 3).
ND2D: Cutting-edge 2D graphics engine driven by a single person (Lars Gerckens), featuring physics integration through Box2D and Napoleon, awesome particle systems, fullscreen fragment shaders, etc. Both official documentation and community support can hardly compete with Starling. Moreover, it’s not “frequently” updated.
Our tests with Starling went really smooth, so we have decided it will be our first candidate. Not that it is much better than ND2D, but overall we liked it more. Maybe ND2D is a bit more optimized but in the end the official support and the more active community weights much more than anything else.
I hope this helps everyone to consider Flash technology when developing their next cross-platform games, now also on mobiles phones and tablets and coming soon everywhere!
Ready to give it a try?