Return to Starling Playback Library

Using Asset Manager to Load Gaf Files

Questions related to Starling playback library should be asked here.

Using Asset Manager to Load Gaf Files

Postby Ali Bati » January 21st, 2016, 9:58 am

Hello,

Is it possible to use Starling's own Asset Manager to load gaf files and do the conversion?

It would make my life easier to manage file structure and load / unload everything in one place.
User avatar
Ali Bati
 
Posts: 4
Joined: January 21st, 2016, 5:28 am

Re: Using Asset Manager to Load Gaf Files

Postby Lê Huy Hùng » January 21st, 2016, 8:21 pm

I also used AssetManager to load gaf file. This is my work flow.
1. Load zip file as normally.
2. Get data is loaded and remove it from assetManager
Code: Select all
var zip:ByteArray = assetManager.getByteArray(name);
assetManager.removeByteArray(name, false);
startConvert(zip);

3. Convert zip file as normally
Code: Select all
      
      private function startConvert(zip:ByteArray):void
      {
         var converter:ZipToGAFAssetConverter = new ZipToGAFAssetConverter();
         converter.addEventListener(Event.COMPLETE, onConvertedLayout);
         converter.addEventListener(IOErrorEvent.IO_ERROR, onErrorLayout);
         converter.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onErrorLayout);
         converter.convert(zip);
      }
User avatar
Lê Huy Hùng
 
Posts: 61
Joined: July 3rd, 2015, 8:32 pm

Re: Using Asset Manager to Load Gaf Files

Postby Ali Bati » February 3rd, 2016, 2:12 am

Hello, thanks for the answer.

Are you working with multiple resolutions?
In that case, how should the workflow be like?
When I export from gaf with 2 different resolution, I get 3 files, anim.png, anim_2.png, anim.gaf
I would like to put .png files in my texture folder.
Right now I have /textures folder. Inside, there are 2 files.
/textures/x1
&
/textures/x2
So, in my case, I'd like to put anim.png in /textures/x1/anim.png and anim_2.png in /textures/x2/anim_2.png
Then, where should I put my .gaf file in the file structure?
(Depending on the scale needed, I load all the texture files inside x1 or x2. I can seperately load .gaf file as well, but not sure if it would work.)
User avatar
Ali Bati
 
Posts: 4
Joined: January 21st, 2016, 5:28 am

Re: Using Asset Manager to Load Gaf Files

Postby Lê Huy Hùng » February 3rd, 2016, 8:39 pm

I don't load seperate .png file and .gaf file, I load zip file and create asset depend scale factor but I think both way is the same.

This is my way
Code: Select all
if (SystemUtil.isAIR)
         {
            var screenWidth:int = stage.fullScreenWidth;
            var screenHeight:int = stage.fullScreenHeight;
         } else
         {
            screenWidth = stage.stageWidth;
            screenHeight = stage.stageHeight;
         }
         var viewPort:Rectangle = new Rectangle(0, 0, screenWidth, screenHeight);
         if (screenWidth / screenHeight >= 1.5)
         {
            Config.SCALE_FACTOR = viewPort.width < 720 ? 1 : 2; // midway between 480 and 960
            Config.STAGE_HEIGHT = 320;
         } else
         {
            Config.SCALE_FACTOR = viewPort.width < 768 ? 1 : 2; // midway between 512 and 1024
            Config.STAGE_HEIGHT = 384;
         }
         Config.STAGE_WIDTH = Math.round(screenWidth * Config.STAGE_HEIGHT / screenHeight);
         
         _starling = new Starling(GameRoot, stage, viewPort, null, Context3DRenderMode.AUTO, "auto");
         _starling.stage.stageWidth = Config.STAGE_WIDTH;
         _starling.stage.stageHeight = Config.STAGE_HEIGHT;
         

And when create zip
Code: Select all
converter = new ZipToGAFAssetConverter();
         converter.addEventListener(Event.COMPLETE, this.onConverted);
         converter.convert(gafAssetFile, 1, Config.SCALE_FACTOR);


This is my example
http://www.mediafire.com/download/6s262 ... Mobile.rar
User avatar
Lê Huy Hùng
 
Posts: 61
Joined: July 3rd, 2015, 8:32 pm

Re: Using Asset Manager to Load Gaf Files

Postby Ali Bati » February 4th, 2016, 2:15 am

That seems like you load the zip file into memory both for x1 and x2 scale. (Even if you are not using them.)
Shouldn't we avoid doing that?
User avatar
Ali Bati
 
Posts: 4
Joined: January 21st, 2016, 5:28 am

Re: Using Asset Manager to Load Gaf Files

Postby Lê Huy Hùng » February 4th, 2016, 8:45 pm

After init asset base on scale factor, zip file was removed. For avoid load both x1 and x2, I think we need a solution from GAF to do it.
User avatar
Lê Huy Hùng
 
Posts: 61
Joined: July 3rd, 2015, 8:32 pm

Re: Using Asset Manager to Load Gaf Files

Postby vadym.mitin » February 5th, 2016, 3:46 am

Guys,

1) If you don't want to put texture atlases for all scale factors into one ZIP - just create two ZIP files. Convert SWF file two times. First time - with conversion settings for scale factor 1. And second time - with conversion settings for scale factor 2. Then you can load corresponding ZIP file that contain only needed texture atlas. This approach is suitable for GAF assets that needs to be downloaded from the WEB. You can automate conversion process by using CLI https://gafmedia.com/documentation/stan ... -interface

2) When you work with GAF assets on the file system (mobile and desktop AIR applications) - keep GAF files in folders (don't keep ZIP files). In this case you can keep texture atlases for several scale factors but load only required one. Example in this post viewtopic.php?f=4&t=506&start=10#p2083

3) If you have an opportunity to load GAF assets for corresponding scale factor at the first run of the mobile application (without including GAF assets into application bundle) - you can combine this two approaches. Just load GAF assets for corresponding scale factor and save them on the device (unzip them and save all files from ZIP into one folder). Then load GAF assets into the application from the file system as described in item 2.

Also keep in mind that approach described in item 2 is more efficient in term of memory usage. In this case GAF restore textures from the file system and don't keep PNG files in the device memory like it do in case when you load GAF asset as ZIP and Starling.handleLostContext = true.
User avatar
vadym.mitin
 
Posts: 254
Joined: December 4th, 2013, 8:00 am

Return to Starling Playback Library

Who is online

Users browsing this forum: No registered users and 1 guest