Box2D with GPU Acceleration for Android

By utilizing the GPU and cacheAsBitmapMatrix this Box2D demo went from a sluggish 18 – 20 fps to a consistent 24 fps! Check out the demo in the video below:

Turning on GPU Acceleration within AIR for Android:
Open the application descriptor XML file associated with your project. Edit the render mode to include gpu instead of auto. The hardware acceleration drop down within the publish settings does not currently modify this property, you need to set it manually.

Using cacheAsBitmapMatrix:

var matrix:Matrix = new Matrix(); // creates an identity matrix 
mySprite.cacheAsBitmapMatrix = matrix; 
mySprite.cacheAsBitmap = true;

Using this code actually flipped my asset vertically on the stage. To correct this I modified the asset vertically within Flash. Using the cacheAsBitmapMatrix significantly increased the performance of the application.

Summary:
Using Box2D, the GPU and cacheAsBitmapMatrix will allow developers to create high performing games with realistic physics. These applications will soon be distributable across multiple mobile platforms. What are you going to create?

GPU Bug on AIR for Android

Correction: Argh. This was a problem in two of my projects, including one I just created but now it’s working on my third project. This may or may not be an issue depending on your setup. I’m going to try and isolate the problem and provide an update. End correction

Not noticing improvement when selecting GPU? It’s because there is a bug in the current pre-release packager for AIR on the Android. Luckily there is a quick work around.

The instructions are clear: add gpu to your descriptor file. Unfortunately Flash re-writes this file EVERY time you open the Air for Android settings window! Selecting the drop down in the Publish Settings also does nothing. So how can we enable hardware acceleration?

Create your project. Open the Android Settings to auto generate the descriptor file. Close the Android Settings window. Open your descriptor file. Add the code above. Save and close the descriptor file. Make that file READ ONLY. Open the Android Settings window again and select publish.

I went from an idle of 30 fps up to 120 fps and active usage from 22 fps to 30 fps. AMAZING difference when you can actually select to use it!

Touchable Framework for Adobe AIR – Sneak Peak!

Let’s face it. The gesture API for Adobe AIR is mediocre at best. Here’s a look at something better, a framework that will allow you to create regions for custom gestures. Controlling where you want to pick up touch events. It will utilize multi-touch, gesture and accelerometer controls all in one package. Control your games and applications in a snap.

The touchable framework can be used in combination with applications that use keyboard controls which makes it compatible with the multi-screen initiative. Stay tuned for more demos!

Box2D on the Nexus One with Adobe AIR

This native application uses the accelerometer to determine the direction of gravity for the Box2D physics engine. It performs quite well given the number of computations and could probably be optimized considerably. Check out the video for a demo on the phone!

Porting the code was the easy part. Configuring Adobe Flash and setting up the Android SDK was a bit more work. Check out Lee Brimelow’s awesome tutorial on http://www.gotoandlearn.com/. If you run into problems finding your device with the adb devices command than check out my previous post. We are going to see some pretty exciting stuff around the corner with Adobe AIR for mobile devices!

Full source code can be found here. You’ll need to run through Lee Brimelow’s tutorial to configure Flash before you get started.