From the first day Flash appeared on the web, people have been using it to create games. In those early days, prior to the release of ActionScript, Flash had a fairly limited feature set, and required quite a bit of lateral thinking to create the logic that games required.
Obviously, Flash has matured over the past 15 years. In fact, it's no longer just an authoring environment; it's an entire platform for creating and deploying applications, content, and videos across browsers and operating systems. And over the years, it has become the de facto environment for creating online games.
Today, approximately 70% of web games are powered by the Flash Platform, along with nine of the top ten games on Facebook, about 70% of the games on Google+, and the top social games from companies like Zynga and EA.
With the release of Flash Player 11 and AIR 2.7, game developers and publishers can now deliver console-quality 2D and 3D games over the web and to connected TV devices. Below we'll explore several new features in Flash Player 11 and AIR 3 that enable developers to create and deliver a new class in gaming experiences.
One of the biggest features within the latest release of the Flash runtimes (both Adobe Flash Player and Adobe AIR) is the new Stage 3D APIs. While 3D content isn't a new concept in Flash, up until this point it has always relied on the CPU of the user's machine to process and render that 3D content, which limited the complexity and amount of rendered 3D content.
With the introduction of Stage 3D for desktop and TV (and soon mobile), the processing and rendering of visual assets can be passed to the user's graphics card, allowing you to increase the performance through the GPU hardware and free up the user's CPU for other processes within your games.
Being able to work with the user's graphics hardware means not only can you render more complex visual elements, and lots more of them, but you can also gain a leap in overall performance due to the reduced load on the user's CPU. Frima Studio used Stage 3D to bring Zombie Tycoon, one of the original six games for the Sony PlayStation Portable Mini, to web gamers (see Figure 1). For another example, check out Tanki Online (see Figure 2), a 3D-multiplayer game from AlernativaPlatform. TankiOnline takes advantage of the 2D and 3D rendering support from the Stage 3D APIs.
The great thing about Stage 3D is that it isn't solely for 3D games; it can also greatly enhance the performance of 2D games. Whether you use it for a fixed camera view of a 3D environment (like a top-down racing game) or to increase standard 2D rendering performance, Stage 3D is particularly useful when using advanced rendering techniques like blitting because it enables you to draw a greater amount of content to the screen than you could in previous versions of Flash Player or AIR.
Even if you don't need to access the user's GPU via Stage 3D, you can use the new asynchronous bitmap decoding in Flash Player. This helps improve the smoothness of animations as the bitmap is decoded on load, not on demand, and enables you to cache those images as needed.
BitmapData objects are no longer limited to a maximum resolution of 16 megapixels (16,777,215 pixels), and the maximum bitmap width/height is no longer limited to 8,191 pixels. What does this mean for you? It translates to better image resolution and optimized performance, particularly for very graphics-intensive apps on high-resolution devices.
One aspect of game development that doesn't tend to get as much focus as the game itself is the game's user interface — that facet of a game that provides additional information about the game's status, such as the score, time remaining, available ammunition, or your character's health status. This information needs to be available without distracting the player from the main game view.
One new feature that adds an extra level of polish to your game's user interface is native cursors, which give you the ability to create custom cursors for your games for a considerable amount of time. The process of hiding the system cursor and replacing it with an alternative (that is active only within the confines of Flash Player) has been somewhat problematic. When using alternative cursors, you were responsible for monitoring when the system cursor should be shown again. This process has also led to Flash-based cursors being orphaned at the edge of the Flash content when the user quickly moved the mouse out of Flash Player or when the user clicked over to another running application. Overall, this was not ideal.
With native cursors, you can work directly with the system cursors, so that when users move out of your content, the custom cursor is automatically replaced with the relevant system cursor. It's fairly straightforward. The following code shows you how to create a static cursor:
[Embed(source="assets/cursors/crosshairs0001.png")] private var Crosshair:Class; var _cursorBitmapData:Vector.<BitmapData> = new Vector.<BitmapData>(1, true); var _cursor:Bitmap = new Crosshair(); _cursorBitmapData = _cursor.bitmapData; var _cursorInfoData:MouseCursorData = new MouseCursorData(); _cursorInfoData.hotSpot = new Point(0,0); _cursorInfoData.data = _cursorBitmapData; Mouse.registerCursor("crosshair", _cursorInfoData);
You are not limited to static cursors. It is just as easy to create animated cursors, which are ideal if you want to indicate a change in your game environment or use the cursor to indicate a target, for example:
var _cursorBitmapData:Vector.<BitmapData> = new Vector.<BitmapData>(5, true); var _cursorInfoData:MouseCursorData = new MouseCursorData(); var _cursor :Bitmap; _cursor = new Crosshair01(); _cursorBitmapData = _cursor.bitmapData; _cursor = new Crosshair02(); _cursorBitmapData = _cursor.bitmapData; _cursor = new Crosshair03(); _cursorBitmapData = _cursor.bitmapData; _cursor = new Crosshair04(); _cursorBitmapData = _cursor.bitmapData; _cursor = new Crosshair05(); _cursorBitmapData = _cursor.bitmapData; _cursorInfoData = new MouseCursorData(); _cursorInfoData.hotSpot = new Point(0,0); _cursorInfoData.frameRate = 20; _cursorInfoData.data = _cursorBitmapData; Mouse.registerCursor("crosshairs", _cursorInfoData);
When developing your games for different platforms, you can now distribute them using the new Captive Runtime feature in AIR 3.
Since AIR 3, you could package your AIR application with all of the AIR runtimes needed to run the app with the help of the new feature "Captive Runtime". So, your application will be able to run without AIR runtimes installed. This is possible on mobile and desktop platforms.
In the past, when users downloaded an AIR application to the desktop or to Android devices, they had to separately download the Adobe AIR runtime as well. Now, all necessary components of the AIR framework are bundled into a self-contained, compiled distributable application – no separate download is required. Developers can automatically package AIR 3 with their applications. Users no longer have to download and update AIR separately. Additionally, with the Captive Runtime option, developers can manage version updates to their application independent of general AIR updates by Adobe.
The examples below show how to compile your game for the desktop by using the AIR Developer Tool (included in the AIR 3 SDK) through the command line. Notice the bundle entry. This tells ADT to include AIR as part of your package.
c:\path\to\air3sdk\bin\adt.bat -package -storetype pkcs12 -keystore c:\path\to\your\certificate.p12 -target bundle mygame.exe mygame-app.xml -C . mygame.swf
On OS X:
/path/to/air3sdk/bin/adt -package -storetype pkcs12 -keystore /path/to/your/certificate.p12 -target bundle mygame.app mygame-app.xml –C . mygame.swf
By including AIR within your game it can make distribution easier and more streamlined as the end user doesn't need to have the AIR runtime installed to play your game.
Getting your content to your users as quickly and easily as possible is always a priority when deploying your content to the web. In the latest version of Flash Player, you can now compress your SWF files with LZMA compression. LZMA compression can reduce your SWF files by 40%, so you can reduce not only the time it takes for your games to download but also the amount of bandwidth required, which helps you get your games to your end users more efficiently.
Some of the features I have discussed thus far are focused on distribution for the desktop or the web. There are also some great new features for mobile devices, such as Android licensing service support, which enables you as a publisher to enforce licensing policies for paid applications that you have published through Android Market.
A lot of game developers use video-based cut scenes in their games, but this can be processor-intensive, especially on mobile devices. With Flash Player 11, you can now use the end user's hardware to decode and render your video content. The key advantages of using Stage Video are that it decreases processor usage and enables smoother video playback and reduced memory usage. On mobile devices (such as Android, BlackBerry PlayBook, and iOS), Stage Video delivers higher fidelity on playback.
As you can see from all of these new features and capabilities, Flash Player 11 and AIR are really optimized for game development. If you'd like to see what game developers are creating with the latest Adobe technologies, visit the Gaming Showcase on Adobe.com.
Mike Jones is a platform evangelist at Adobe.