Or should I say: My first contribution to the Open Source Flash community? Both are true.

In case you don’t know what Starling is, it’s a open source 2D GPU Hardware accelerated Framework for Flash that may allow you to take advantage of the benefits that come with the Stage3D class, but for making 2D content.

Enough with the Starling introduction, what I did was to add a little extension that I think will be greatly appreciated, specially by mobile developers.

As you know, GPU acceleration is possible only if you upload textures (bitmaps) to the GPU, so no vectorized content is allowed (no traditional flash display list here).

Let’s say you are developing a game. You want to publish it as an iOS game for iPhone, iPad, and also as an Android App and as a BlackBerry playbook as well. You’ll have to handle a lot of screen sizes. What you want to do is to have only on version of the code and assets and publish it for every device without having to maintain different versions.

If you develop the game using the most common approach (using Sprite Sheets and Texture Atlasses) you’ll have to make your sprite sheets taking the biggest resolution of your target devices (for instance the iPad) and scale it down on the rest of the devices at runtime. That is a good approach but it would require more memory than it would need for most of the devices that it will be running in. And if in the future a new device with a bigger screen hit the market, you’ll have to make bigger assets recompile the game.

Starling lets you create Texture Atlasses at runtime by using bitmap textures. So why can’t you take advantage of your vectorized assets by having then as vectors (Using regular Sprites and MovieClips), scaling them to the size you really want (including filters), and then creating a Texture Atlas?

Introducing the Dynamic Texture Atlas Generator

This tool will convert any MovieClip containing other MovieClips, Sprites or Graphics into a starling Texture Atlas, all in runtime. By using it, you won’t have to statically create your spritesheets. Just take a regular MovieClip containing all the display objects you wish to put into your Atlas, and convert everything from vectors to bitmap textures. This could save you a lot of time specially if you’ll be coding mobile apps with the starling framework.

I’m planning to add the same functionality for converting system or embedded fonts into bitmap fonts as well.

Where can you find it?

How to use

Use the static method DynamicAtlas.fromMovieClipContainer:

DynamicAtlas.fromMovieClipContainer(swf:flash.display.MovieClip, scaleFactor:Number = 1, margin:uint=0, preserveColor:Boolean = true):starling.textures.TextureAtlas


  • swf:flash.display.MovieClip – The MovieClip sprite sheet you wish to convert into a TextureAtlas. It should contain named instances of all the MovieClips that will become the subtextures of your Atlas.
  • scaleFactor:Number – The scaling factor to apply to every object. Default value is 1 (no scaling).
  • margin:uint – The amount of pixels that should be used as the resulting image margin (for each side of the image). Default value is 0 (no margin).
  • preserveColor:Boolean – A Flag which indicates if the color transforms should be captured or not. Default value is true (capture color transform).

As you can see, the only required parameter is the first one: The sprite sheet Movie Clip. Inside of it (in a single frame) you should put every one of the MovieClips you wish to upload to the GPU, naming every instance. At the end of the process you’ll have a Starling Texture Atlas containing every asset as a texture.

Take a look at this example:

// Assuming that you have a MovieClip Sprite sheet named "mc" with all your assets inside
// Enclose inside a try/catch for error handling:
try {
var atlas:TextureAtlas = DynamicAtlas.fromMovieClipContainer(mc);
} catch (e:Error) {
trace("There was an error in the creation of the texture Atlas. Please check if the dimensions of your clip exceeded the maximun allowed texture size. -", e.message);

Some credits

This little project was only possible thanks to the inspiration (and code) I got from:

I really hope that this tiny contribution may help flash developers to easily enter the GPU accelerated world without having to stop using the display list and the Flash authoring IDE for asset creation. Vector content is still really useful for a lot of things.