Zipped Assets

author:
Daniel Sperl
description:
Unzip individual assets right while they are loaded
compatible:
v2.4
tag:
assets, zip, AssetManager
homepage:
https://gist.github.com/PrimaryFeather/6c9874fb2c38c8376554c51f47b91777

Overview

This extension requires Starling 2.4 with its new AssetManager.

Some assets, especially JSON and XML files, can take up quite a lot of disk space. That can increase the install size of an app or game significantly.

Fortunately, though, many of those assets also compress very well when zipped – let's exploit that! With this extension, you can compress individual assets as zip-files and let them be decompressed by the AssetManager.

Usage

First, use a ZIP-tool of your choice to compress the relevant assets. Each zip file must contain one (and only one!) asset. The file name of the zip file is actually not relevant – the AssetManager will only look at the filename found inside the zip-file. Nevertheless, I recommend the following name scheme so that you easily see what's inside:

  data.json => data.json.zip
  font.xml => font.xml.zip
Don't blindly zip each and every file. For example, zipping doesn't make MP3, JPG, PNG or ATF files any smaller. If you zip those files, you'll just make the load process take more time and memory.

To “install” this extension in your game, simply download the ZipLoader class from the Gist-link above and copy it to your game project. Furthermore, you need a copy of the FZip library. Download the swc library from here and add it to your project, as well.

Using the class is really easy: you simply assign a new ZipLoader instance to the AssetManager's dataLoader property and, bam, it will unzip files automatically and transparently!

// instantiate the standard AssetManager
var assets:AssetManager = new AssetManager();
 
// assign the "ZipLoader"
assets.dataLoader = new ZipLoader();

When that's done, you use your AssetManager just like before, both for zipped and unzipped files.

assets.enqueue(appDir.resolvePath("assets/font.png"));
assets.enqueue(appDir.resolvePath("assets/font.xml.zip"));
assets.loadQueue(onComplete);

Happy zipping!

Changelog

  • 2018/04/18: First public version.
  • 2018/06/04: Moved all the code into the DataLoader extension.

Source Code

User Comments

Feel free to edit this part of the page if you want to add information that's lacking in the above description.
Questions are better asked in the forum, though.

  extensions/zipped-assets.txt · Last modified: 2018/06/04 12:41 by daniel
 
Powered by DokuWiki