Monday, April 16, 2012

Starling Framework Extension (Games)

"Starling is a port of an iPhone Development Framework named Sparrow written by Gamua that lets developers take advantage of the hardware capabilities of coding for OpenGL, but are abstracted to Classes and APIs that are familiar to ActionScript developers."



But why should I use iPhone Development workflow? Why should we use Texture packager and tools alike to export all our swf animations to huge bitmap called TextureAtlas? 


 Is this Flash way?
Why should I load 2.28MB picture in memory for 20 frames instead 30KB something swf or swc? What about if I want to scale it. Should I create and load Atlas for every size I've.

What about if I embed swc or swf with animation vector data and use it to create texture's bitmap data when ever I need and with size I need. I've develop this logic for AnimatedClip and can be 99%(*) applied with Starling.MovieClip too, so would be good to check my previous post.


(see embedded CreatureRageMode.swf and included CreatureNormalMode.swc)

public static function getMovieClipTextures(name:String,preserveColor:Boolean=false,processFilters:Boolean=true):Vector.
        {
            
                        
             if (sTextures[name] == undefined)
            {
                
                var data:*= new Assets[name]();
                
                _stage.addChild(data);
               sTextures[name] = generateTextureFrames(data);
                _stage.removeChild(data);
            }
            
            return sTextures[name];
        }

Standard 2D MovieClips are added to stage, frames converted to Textures and removed. Textures are used for creation of Starling.MovieClip.

*as you can see Starling.MovieClip should be tweaked for pivots and using different size bitmaps in different frame.


Source: download




2 comments:

  1. Hi Alex, nice solution! There's also the Dynamic Texture Atlas Generator, a Starling extension I made some months ago.
    https://github.com/emibap/Dynamic-Texture-Atlas-Generator
    Cheers!

    ReplyDelete