GameSalad Best Practices: Asset Pre-Loader

October 5 2011, 4:30pm

Billy Garretsen leads GameSalad’s internal Game Team One. He has been an independent game designer for more than ten years. He’s helped develop titles for all the major game consoles, as well as numerous games for PC and mobile platforms. His most recent GameSalad title was 2 Broke Girls, currently available on GameSalad Arcade, iOS, Facebook, and the Chrome Web Store. In GameSalad Creator 0.9.80, developers will be able to control when their art assets get loaded into memory by toggling a new self attribute, “PRELOAD ART”, on and off in their actors. With this attribute set to true, all of the images associated with an actor will be loaded into memory at the time the scene is loading. If a user’s scene has a lot of on-screen elements and artwork loading can sometimes be annoyingly long. Though, with PRELOAD ART turned off (checked false) the user can influence when an art asset is loaded into memory through their actor logic. The Results: Significantly shorter scene loading times. Pro Technique #1: Using Null Textures and Change Image Behavior A null texture is one that contains no art – as in a fully transparent image. I create a very small null texture for almost every project I work on, as they are useful beyond this particular application. I usually keep it really small: 16×16 pixels.

One thing you can try to shorten your load times upfront is to take all of your actors in a scene and give them this null texture as their base texture. Then the first behavior in their logic stack can be a CHANGE IMAGE or CHANGE ATTRIBUTE>self.image where you set their actual texture. Right when the scene finishes loading and starts running your invisible textures will instantly load in and switch to the actual art. The switch should happen so fast that you cannot even see it, resulting in lightning fast scene loading.

Pro Technique #2: Selective/Trigger-based art loading The previous technique is a really great way to get into your scene quickly and instantly load a bulk of textures. What if you don’t want them to load all at once though? You can select precise moments for loading in new art within your scene by putting your CHANGE IMAGE, CHANGE ATTRIBUTE>self.image, and ANIMATE behaviors inside of a timer or rule condition. Timers can allow you to secretly load in art that is not seen or used until later within that scene without a big visible hitch at the time the scene starts running. Using an arbitrary timer value such as “After 5 seconds” works well unless you have specific timer offset requirements. Similarly, rule conditions that will trigger the art loading allow you to wait until a later time after the scene has loaded to introduce this new art to memory. For example, if you have background elements in a scene that do not appear until your character reaches a certain point in a level, then it is recommended to trigger the loading of the art when the player position is close by. This could look something like “If PlayerXPosition is greater than 480 then CHANGE IMAGE to BackgroundArt4.png”. Though, this will only be effective if your base texture was a null or dummy texture as described above.

Knowing when to use Preloading OFF techniques While these techniques result in lightning fast load times in between your scenes, it is important to use them wisely and sparingly. It is not recommended to attempt to load in art for an actor during a moment of intense action or logic calculations. The general rule of thumb is to get your players into your game as fast as you can from the moment they click the app icon. It is recommended to use these techniques for menus and introductory screens to get your players to the core game scenes faster. Then it is at your discretion how much art preloading occurs for core scenes; players will be more lenient if a level scene takes a few seconds to load in. Preload Art Attribute and Asset Manager: The Yin and the Yang Another feature being added to GameSalad Creator 0.9.80 is the back-end asset manager, which scrubs through the RAM, finds unused textures and automatically dumps them out of memory. This will not destroy any actors in the scene and at the time the texture is needed again, it will be reloaded into memory seamlessly. This will greatly reduce game crashes on iOS devices since the asset manager will prevent your games from exceeding the memory cap. Both of these features combined will now give users much better performance in their games and far more control over their asset optimization. Screenshot Gallery: