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 (or the latest head revision) with its new AssetManager. Furthermore, it only works with AIR (not in the Flash Player).

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. Make sure to add the “.zip” extension to the complete original filename, e.g.

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

In your app or game, you need to use the custom ZippedAssetManager class that's part of this extension. I recommend you simply add the respective file directly to your game code; then instantiate it like this:

var assets:AssetManager = new ZippedAssetManager();

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);

There's only one thing missing; this extension depends on the FZip library to do the hard work. Download the swc library from here and add it to your project, as well.

Happy zipping!

Changelog

  • 2018/04/18: First public version

Source Code

If you are using Gist, you can add the source code of your extension easily with the following code. Just replace the number in parenthesis with the Gist ID.

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/04/18 13:01 by daniel
 
Powered by DokuWiki