Starling Framework – Use flash.display.MovieClip with DynamicTextureAtlasGenerator
Starling Summary
- Really Fast Rendering – Really fast! See these demos (Whack! Game, Amazing Particles, Fantastic Sprites)
Cons
- Name collisions. Why TODAY we have both starling.display.MovieClip AND flash.display.MovieClip in use, I’m not sure. It sucks and leads to ugly coding and the requirement to use the complete path for each everywhere (not just in the imports). Same problem with Image, same with Sprite, maybe more… It is Ugly. I’d recommend using a custom namespaces, or globally unique class names (ex. SMovieClip). But who am to complain? Well, I created the greatest AS3 API SDK yet, but that’s another story.
- Rasters Are Required – Starling natively requires that NONE of your graphics be vector. You must draw them in raster or convert them from vector to raster using a 3rd party tool (ex. TexturePacker, SpriteLoc) before you bring them in as raster graphics (or lists of raster graphics for animations) That sucks! Its horrible! Damn! I miss flash.display.MovieClip with its easy create-embed-edit round-trip from Flash. If only there was a solution*…
*Update: Now There Is A Solution (See Below)!
Introducing the Dynamic Texture Atlas Generator (DGAT)
Yeah, let’s call it DTAG. Its long. It was created by god, aka Emiliano Angelini of Emibap. It allows you to utilize vector graphics for Starling. Yay! You can pull them from the library via linkage name, you can load them in an external swf (I think), or you can embed them from an external swf (That’s what I like to do).
Vector Source For Starling Vs Raster
Pros
- Lower file-size (i.e. faster download)
- Scalable (at run-time)
- Reuse of assets (at run-time use same source at with various sizes, effects, translations, etc… applied)
- Easier draw-embed-update round-tripping
Cons
- Requires some one-time up-front processing (potential delays on a large project)
- Requires larger amounts of RAM (I think)
Challenges of Multi-screen Development
The benefits of a one-vector to many-raster (various dimension/crops) is even more evident when considering multi-screen development. As of March 2012, a developer creating an app for iOS needs to consider at most these screen sizes – iPhone 3GS, iPhone 4, iPad1/2, iPad3. All all of those in portrait and layout. Now imagine launching that same app for Android (*MANY* devices) and Blackberry Tablet too. Wow! Now that is considerable of a) storage space and b) asset creation/management. Creating some or all of these assets in vector and converting them would certainly be an interesting proposition.
Tutorial with Dynamic TextureAtlas
I created a demo showing an effective, clean, scalable solution for assets in starling. The demo shows an animated boy loaded with method 1 below. And using method 2 it shows a shape with animated blur (animated on timeline in flash) and it shows a static shape that was drawn in Flash. All assets are in the same swf which was embedded into the FLA.
Click here to see the running demo of that image (Flash Player 11 required).
The process is here;
- Setup Starling “World” in your application
- Create Assets In Vector A Fla, Publish SWF
- Embed SWF (via AssetManager.as) into application
- Convert Vector Assets into Raster dynamically at run-time (I show the 2 methods I like most).
Asset Setup
Here is the FLA containing all the assets. Note the linkage names in the library. From this fla we publish the assets swf.
Here is the AssetsManager.as class which I use to embed the linkage names from the assets swf.
Starling Setup
First we declare the document class for our application and setup Starling.
Then we create the game. As you see, there isn’t much to it.
Here is the first method.
And here is the second method.
Blue Sky
When brainstorming possible additions to the API, consider this. What if the challenges of the conversion processing time and the RAM required (which we mention as a cons above of the Dynamic workflow) could be offset by additional functionality. Let’s say a way for the API to convert the assets one-time-per-device and then store them.
The following API does not exist yet. It is just an idea.
var myTextureAtlas : TextureAtlas;
if (DynamicAtlas.localStorage.hasTextureAtlas (blahSettingsForASpaceshipAtCertainSize...) == true) {
//LOAD FROM LOCAL STORAGE
myTextureAtlas = DynamicAtlas.localStorage.getTextureAtlas (blahSettingsForASpaceshipAtCertainSize...)
} else {
//CONVERT AND STORE
myTextureAtlas = DynamicAtlas.fromClassVector (blahSettingsForASpaceshipAtCertainSize...);
DynamicAtlas.localStorage.setTextureAtlas (myTextureAtlas , blahSettingsForASpaceshipAtCertainSize...);
}
myBoyAndDogRunning = new MovieClip( myTextureAtlas.getTextures() , 60);
Next Steps
- Intro To The Starling The Framework For AS3
- Download the full source of The Dynamic Texture Atlas Generator
- Download the full source of the demo shown in this post (See ‘Member Resources’ below).
Member Resources
You must be a 'Free Member' to see this content. With your access you will enjoy members-only content like this, HD video tutorials, and access to complete source code.
Ready To Join?
- Sign up for 'Free Member' level now. Its free!
- Sign up for 'Paid Member' level to enjoy much, much more! (Invite Only)
- Log in and enjoy!













Thanks for this article Samuel
There are some developers who say that using dynamic Atlasses is not a good solution because of the time consuming initial process. But even if you end using static Atlasses, you can make quick prototypes of your game using this approach.
It will be really interesting to have stats of both initialisation time and memory consumption for a sample App, using a static and then a dynamic Atlas.
I was wondering if something like this was going to be created. I even considered building it myself!
I still think this will be a good workflow for sprite sheets. Reducing file size is important! (Maybe not so much for mobile apps- but for the web its still a good process) As far as waiting initially for something to process. Flash handles this like a champ. Loading large atlases is also a user-time consuming process.
Consider processing the content progressively as the user needs it. Rather than all at once! You don’t want a whole lot of back and forth between the GPU, but a little here and there can help smooth it out.
Also, consider concurrency that is coming to Flash. In the future you might be able to spur up a AS worker thread and process your atlas. Meanwhile you can continue to allow the user to work on something else or display something useful while it processes.
You can sort of do this currently… Create a psuedo-thread that processes only some of the data across many frames. This helps to keep the application feel performant.
Hi. Thanks for the great tutorial, I’m having a problem though. I’m getting an “Error #1034: Type Coercion failed: cannot convert Assets_SpriteSheet@2e10921 to flash.display.MovieClip” error when I’m creating the Dynamic Atlas using the second method. Am I missing something obvious? Thanks
I’ve fixed it now. I’ve ended up wrapping everything in an SWC and it’s all working.
can i get the fla sources ? i’m a beginner
Hi,
thanx for the great demo!
But there is something strange, never seen something like this before:
Game.as/
function _doDynamicTextureAtlas__FromEmbeddedSWFSymbol()
Line ~48:
undefined = new Class();
FB 4.6 shows the Error:
1049: Illegal assignment to a variable specified as constant.
Game.as
Flex Problem
when I comment this out it works, otherwise not.
Use “undefined” as a class name – whats the Idea with that ??
thanks!
Hi,
Thats the right direction! However i’ve been using DMT and even though it is more recent and still alpha 0.15 it has more features and assembles whole Atlases, supports 9-scale and assembles whole hierarhies of assets.
Consider using this: http://www.xtdstudios.com/dmt.html
Also I talked with the developpers a lot and they are very nice and approachable. So you should definately take a look.
thanks!
First of all thank you for your sharing,this is very good
I want to know this kind of performance with the use of pure bitmap sequence to realize how big is the difference on performance
You’re so awesome! I do not suppose I have read through something like this before. So wonderful to discover another person with some genuine thoughts on this issue. Really.. many thanks for starting this up. This website is one thing that is needed on the internet, someone with a little originality!
Hi folks,
Is there is a way to load the swf asset dynamically and extract the vector class and and use it in the Dynamic Texture Atlas Generator, becoz all i see here we need to embed the swc, which will increase the app pack size, i tried loading swf in IOS it doesn’t work, please suggest.