• Home
  • Contact
  • Careers
  • Socialize With Us:
  • Send us Mail
  • Follow us on Twitter
  • Join our Facebook Group
  • /
  • Linkedin
  • /
  • Vimeo Videos
  • /
  • Youtube
  • /
  • RSS Feed
  • Search Site

  • About UsAwards & Bio
  • PortfolioOur Latest Work
  • TrainingTips & Tutorials
  • BlogGreat Articles

You are here: Home / News / Industry News / Starling Framework – Use flash.display.MovieClip with DynamicTextureAtlasGenerator

Starling Framework – Use flash.display.MovieClip with DynamicTextureAtlasGenerator

Category: Industry News, Quick Tips
Starling is a 2D GPU-Accelerated AS3 framework For Flash. It rocks, and you can ready my article “Intro To The Starling The Framework For AS3” for more info. I’m new at Starling, but so far here is a quick summary;

Starling Summary

Pros
  • 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;

  1. Setup Starling “World” in your application
  2. Create Assets In Vector A Fla, Publish SWF
  3. Embed SWF (via AssetManager.as) into application
  4. 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.

// Align the Flash Stage
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

// Setup The 'Engine'
_starling = new Starling (Game, stage);
_starling.enableErrorChecking = true;
_starling.start();

// Add Small Box of Framerate Statistics
addChild( new Stats() );

Then we create the game. As you see, there isn’t much to it.

// --------------------------------------
// Constructor
// --------------------------------------
/**
 * 
 * 
 */
public function Game(){
	
	// SUPER
	super();
	
	// Method 1 - Feels more like traditional Flash (good!)
	_doDynamicTextureAtlas__FromEmbeddedSWFSymbol();
	
	// Method 2 - Puts several 'MovieClips' of graphics into one atlas. This is good for GPU.
	_doDyanmicTextureAtlas__FromEmbeddedSWFSpriteSheet();
	
	
}

Here is the first method.


/**
 * Dynamic Atlas From Source: An Embedded MovieClip Symbol From SWF
 * 
 * This is totally awesome. Now I can keep my graphics as vectors. 
 * 
 */	
private function _doDynamicTextureAtlas__FromEmbeddedSWFSymbol () : void
{
	
	try {
		
		// 1. Setup Properties
		var assets_vector_class:Vector.<Class> = new Vector.<Class> ();
		
		//
		assets_vector_class.push (AssetManager.BoyAndDogRunning); 	//WARNING - MUST HAVE 2+ 
																	//FRAMES TO AVOID ERRORS
		
		//
		var scaleFactor_num:Number 			= 1;		//DEFAULT
		var margin_uint:int					= 0;		//DEFAULT
		var preserveColor_boolean:Boolean 	= true;		//DEFAULT
		var checkBounds_boolean:Boolean 	= false;	//DEFAULT
		
		// 2. Create Atlas From VectorClass
		var myTextureAtlas : TextureAtlas = DynamicAtlas.fromClassVector (	
			assets_vector_class, 
			scaleFactor_num,
			margin_uint,
			preserveColor_boolean, 
			checkBounds_boolean);
		
		// 3. Create MovieClip From Atlas
		var TOTAL_TO_CREATE : uint = 1;		//OR JUST CREATE 1
		var myBoyAndDogRunning : MovieClip;
		for (var i_uint : uint = 0; i_uint < TOTAL_TO_CREATE; i_uint ++) {
			
			myBoyAndDogRunning = new MovieClip( myTextureAtlas.getTextures() , 60);
			myBoyAndDogRunning.x = Math.random()*400 + 50; myBoyAndDogRunning.y = 100;
			addChild(myBoyAndDogRunning);
			
			// 4. Juggler will 'step' the animation forward each 'ENTER_FRAME'
			Starling.juggler.add(myBoyAndDogRunning);
		}
		
		
		
	} catch (e:Error) {
		
		trace ("ERROR");
		trace (	"There was an error in the creation of the texture Atlas. ");
		trace (	"Please check if the dimensions of your clip exceeded the maximun ");
		trace (	"allowed texture size.");
		trace ("[[ " + e.message + " ]]");
		
	}
	
}


And here is the second method.

/**
 * Dynamic Atlas From Source: An Embedded MovieClip From SWF Which CONTAINS MovieClips
 * 
 * The SpriteSheet is just a MovieClip in the SWF with some clips within it. 
 * The clips within have instances names. We use those instance names for 'getTextures()'
 * 
 */	
private function _doDyanmicTextureAtlas__FromEmbeddedSWFSpriteSheet () : void
{
	
	
	try {
		
		// 1. Setup Properties
		var mySpriteSheet : *  = new AssetManager.SpriteSheet ();
		
		// 2. Create Atlas From a MovieClip Containing The MovieClips we really want
		var myTextureAtlas:TextureAtlas = DynamicAtlas.fromMovieClipContainer(mySpriteSheet, 1, 0, true, true);
		
		// 3a. Create MovieClip From Atlas
		var myCircle : MovieClip = new MovieClip(myTextureAtlas.getTextures("myCircleInstance"), 20);
		myCircle.x = 200; myCircle.y = 300;
		addChild(myCircle);
		
		// 3b. Create MovieClip From Atlas
		var myAmoeba : MovieClip = new MovieClip(myTextureAtlas.getTextures("myAmoebaInstance"), 2);
		myAmoeba.x = 350; myAmoeba.y = 300;
		addChild(myAmoeba);
		
		// 4. Juggler will 'step' the animation forward each 'ENTER_FRAME'
		Starling.juggler.add(myCircle);
		Starling.juggler.add(myAmoeba);
		
		
	} catch (e:Error) {
		
		trace ("ERROR");
		trace (	"There was an error in the creation of the texture Atlas. ");
		trace (	"Please check if the dimensions of your clip exceeded the maximun ");
		trace (	"allowed texture size.");
		trace ("[[ " + e.message + " ]]");
		
	}
	
}

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

'Free Member'-Only Content

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)
Already A Free Member?
  • Log in and enjoy!

10 Responses to Starling Framework – Use flash.display.MovieClip with DynamicTextureAtlasGenerator

  1. Emiliano Angelini says:
    March 10, 2012 at 4:00 pm

    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.

    Reply
  2. Elliot Geno says:
    March 22, 2012 at 5:40 pm

    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.

    Reply
  3. John Bower says:
    April 15, 2012 at 10:42 am

    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

    Reply
  4. John Bower says:
    April 15, 2012 at 2:38 pm

    I’ve fixed it now. I’ve ended up wrapping everything in an SWC and it’s all working.

    Reply
  5. richard ndumu says:
    May 12, 2012 at 3:55 pm

    can i get the fla sources ? i’m a beginner

    Reply
  6. Markus Klinger says:
    January 28, 2013 at 11:37 pm

    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!

    Reply
  7. Artifexx says:
    February 15, 2013 at 10:31 am

    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!

    Reply
  8. 刘刚 says:
    March 18, 2013 at 4:11 am

    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

    Reply
  9. wizard on wizard of oz says:
    April 24, 2013 at 6:50 am

    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!

    Reply
  10. megnathamuthan says:
    April 25, 2013 at 11:59 am

    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.

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Free Member Login

You are not currently logged in.






» Register
» Lost your Password?

Support Our Sponsors

Category

  • Industry News
  • Standards & Best Practices
  • Full Tutorials
  • RMC News
  • Events

Tag

3D AIR API AS3 AS3.5 Business C# Debugging Experimental Flash Flex Games HTML5 Java Loom Mobile Optimization Project Planning PushButtonEngine Robotlegs Smash Unity3D WordPress WordPress Plugin

Brazilean Developers

  • Abendita.com
  • dclick.com.br
  • dm9.com.br
  • Fellyph Cintra
  • IgorCosta.org
  • MonadaSolucoes.com.br
  • PossibleWorldwide.com.br
  • Unit9.com

Developers

  • Adobe Blogs
  • Ben Forta
  • Colin Moock
  • Enrique Duvos
  • Flash Mobile Blog
  • Jess Freeman
  • Kevin Hoyt
  • Lee Brimelow
  • Paul Trani
  • Quasimondo
  • Renaun Erickson
  • Ryan Stewart

Free Assets

  • Free Sounds
  • HasGrafics

HTML5 Games

  • Closure JS Library
  • Eloquent JS Manual
  • Game Framework – CraftyJS
  • Game Framework – EaselJS

Italian Developers

  • alchimedia.com
  • corlan.org/
  • creativesource.it
  • dimix.it
  • fabiobiondi.com
  • gnstudio.com
  • Interpreting-tech.com/bemobile/
  • leonardorisuleo.info
  • lucamascaro.info
  • mart3.org
  • mxml.it
  • nxn.it
  • pirosoft.it
  • Preload.it
  • sonnati.wordpress.com/
  • webgriffe.com

Products

  • Adobe.com
  • Amazon Kindle E-Reader
  • ElectroServer
  • F*CSS
  • Flash Development Toolkit (FDT)
  • O'Reilly PureMVC Book
  • Samsung Galaxy Tablet
  • Unity3D

RMC

  • RMC Consulting

Spanish Developers

  • Flash Adictos
  • HTML Cinqo
  • Tutoriales Flash

Tutorial

  • Active Tuts
  • AS3-to-Unity3D Training Videos
  • Doing 2D in Unity3D
  • Learning C#
  • Unity3D Tutorials

Unity3D Games

  • AS3-to-Unity3D Training Videos
  • Doing 2D in Unity3D
  • Learning C#
  • Matt Eley's Blog
  • Unity3D
  • Unity3D Tools
  • Unity3D Tutorials

I Am Great!

   

Latest Portfolio

  • Live Media Steaming ApplicationMay 20, 2013, 5:06 am
  • Museum Kiosk Touch ScreenNovember 15, 2012, 9:00 pm
  • Happy Birthday Mobile AppMarch 14, 2012, 5:55 pm
  • Official Robotlegs MVCS DiagramFebruary 24, 2012, 1:36 am

Latest News

  • Unity3D Top 5 News AnnouncementsMay 24, 2013, 3:10 am
  • Tutorial Series: Unity3D / C#May 24, 2013, 1:14 am
  • Intro to Loom Game EngineMay 19, 2013, 6:48 am
  • Unity3D for Game DevelopmentMay 13, 2013, 4:25 pm

Latest Tweets (@srivello)

  • ARTICLE LAUNCHED -- Introduction to Unity3D - http://t.co/20SisNxVPC
  • The internet in Kuala Lumpur at 6Mbps is a totally different product than at the typical 1Mbps of archipelagic Asia. http://t.co/EV010rXILx
  • Very inspired by the #XBoxOne. The presentation's focus on non-game features is both bold and a bit scary as a gamer.
  • 3 hours into my Centipede clone using #2DToolkit for #Unity3D http://t.co/5yWsMQvHEU

© Copyright 2006 - 2013 - Rivello Multimedia Consulting - Flash / HTML5 / Unity3D Game And App Development With Tutorials