If you upgraded to Starling 1.7 and your app is broken, check your assets manager

Categories Actionscript

After updating to Starling 1.7, my game stopped compiling. After a quick debugging, I found the problem in the assets manager. Narrowing it down, it seems that the getTexture returns null if I try to load an atlas texture.

To fix it, change:

ActionScript

  1. var elemTexture:Texture = resources.assets.getTexture("elements");         
  2. var elemXml:XML = new XML(resources.assets.getXml("elements"));
  3. var elemAtlas:TextureAtlas = resources.assets.getTextureAtlas("elements");

To:

ActionScript

  1. var elemAtlas:TextureAtlas = resources.assets.getTextureAtlas("elements");

My assets are named: “elements.png” and “elements.xml”

In my game resources is a separate class that just loads all the elements, and the assets var is set to public, it looks like this:

ActionScript

  1. package com.cosmindolha.mathrun
  2. {
  3.     import flash.events.TimerEvent;
  4.     import flash.filesystem.File;
  5.  
  6.     import starling.events.Event;
  7.     import starling.utils.AssetManager;
  8.  
  9.     /**
  10.      * ...
  11.      * @author ... Cosmin Dolha ~ contact@cosmindolha.com
  12.      */
  13.     public class Resource
  14.     {
  15.         public var assets:AssetManager;
  16.        
  17.         private var disp:DataDispatcher;
  18.                
  19.         public function Resource(dd:DataDispatcher)
  20.         {
  21.             disp = dd;
  22.  
  23.             assets = new AssetManager();
  24.            
  25.             assets.keepAtlasXmls = true;
  26.    
  27.             var appDir:File = File.applicationDirectory;
  28.            
  29.             assets.enqueue(appDir.resolvePath("assets"));
  30.            
  31.             assets.addEventListener(Event.IO_ERROR, onError)
  32.  
  33.             assets.loadQueue(function(ratio:Number):void
  34.             {
  35.             if (ratio == 1.0)
  36.             {
  37.                 //trace("asstes loaded");
  38.                 disp.assetsLoaded();
  39.             }
  40.             });
  41.         }
  42.  
  43.         private function onError(e:Event):void
  44.         {
  45.                 trace(e.data);
  46.         }
  47.        
  48.     }
  49.  
  50. }
Share this
Facebooktwitter

No Comments

Leave a Reply

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