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?

5 thoughts on “Box2D with GPU Acceleration for Android

  1. I just put my first AIR app on my EVO last night, with the intent of testing performance. I’m actually using Box2D as well. I think I added gpu support correctly, but am not sure. In order for adt to compile the apk file, I had to put the tag in the (or whatever that is) section of tags, not at the top of the file or anything. Is that the right place for it?

  2. The setting is located under: application -> initialWindow -> renderMode. This line should already be in your xml file but with the value of ‘auto.’ Feel free to send over an e-mail if you’re not able to get it to work. Congrats on getting into AIR for mobile, it’s a blast!

  3. Hey Derek,

    You’re correct. I could have passed the parameters into the matrix for rotation. This actually turned out to be a bug with the cache as bitmap matrix class and was fixed in the latest release build of AIR for Android. I’ve done a little bit with matrix manipulation but plan to do some more research one of these days. Thanks for the link!

Comments are closed.