-
Notifications
You must be signed in to change notification settings - Fork 6
Working with assets
Flambe has very smart concept of working with assets, if you understand it allows you to quickly load, add and replace assets.
Within a default setup, you should put all your assets inside your projectfolder/assets.
Inside the assets folder you can create directories. These are your assetpacks. You have to load them separately. In the default flashdevelop project, you have one assetpack called "global", If you want to load assets later on, create a different folder (assetpack).
When you have loaded an assetpack, all files in it are instantly available (which is pretty nice). If you want to exclude file under some conditions, you also have to use other assetpacks; organize your folder wisely.
Inside the assetpack, you can put images, sounds and other files.
Anything that is placed in your assetpack folder, is included when you load it.
All assets are moved to deploy/web after compilation. A list of assets is created internally. You should never mess in the assets of the build/web folder, they are overwritten on a compile AND you can get runtime errors if files missing in that folder, because then you broke the 'list of assets'. To ensure having a clean build/web folder, you can safely remove it before a compile, but in normal conditions, Flambe manages this for you.
Important note If you removed/changed/moved/renamed a file, you should always recompile+test if it still works.
A Manifest object lists assets and where they can be found. Typically Manifest.fromAssets()
is used to
create a Manifest from files in the project's assets directory, but they can also be dynamically
constructed, to load assets from other sources over the web.
var loader = System.loadAssetPack(Manifest.fromAssets("foldername"));
loader.progressChanged.connect(function () {
trace("Download progress: " + (loader.progress/loader.total));
});
loader.get(function (pack) {
// Download complete, use the pack to start the game
});
var texture = pack.getTexture("myImage"); // returns the texture of myImage.jpg or myImage.png from the assetpack
To show the actual image, read Working with images.
You have to encode all sounds in supported formats: m4a, mp3, ogg. Flambe will auto-magically select the right sound for the current platform; there is no need to provide an extension.
var sound = pack.getSound("mySound");
To play the sound and control volume and playback, read Working with sound.
Need a JSON/XML or any other extension? Make sure you encode it to JSON or XML, File.toString()
returns the file content as String.
var myJson:Dynamic = Json.parse(pack.getFile("data.json").toString());
var myXML:XML = Xml.parse(pack.getFile("data.xml").toString());
To load external assets, you need to create a Manifest, add assests using an identifier and URL to it, then let System load it. You can use the identifier later to get it back out of the Manifest after loading.
var manifest = new Manifest();
manifest.add("textfile", "http://www.mydomain.com/myFile.txt");
// give manifest hint 'Image'; needed since lack of extension
manifest.add("facebookPhoto", "https://graph.facebook.com/markknol/picture", Image);
System.loadAssetPack(manifest).get(function (pack)
{
trace(pack.getFile("textfile").toString());
trace(pack.getTexture("facebookPhoto"));
});
Note; you can have crossdomain issues if the domain doesn't allow others to load content from their server.
To setup multilanguage assetpacks, you need a default assetpack. For example, call the assetpack (folder) "content". Then, you could use this folder structure:
assets/content/ // default
assets/content_nl-NL/ // Dutch
assets/content_en-US/ // English
assets/content_pt-BR/ // Brazilian Portuguese
Then use Manifest.fromAssetsLocalized
instead of Manifest.fromAssets
and provide a language code.
// Gets the RFC 4646 language tag of the environment.
// For example, "en-US", "pt", or null if the locale is unknown
var languageCode = System.locale;
var loader = System.loadAssetPack(Manifest.fromAssetsLocalized("content", languageCode));
loader.get(function (pack) {
// Download complete. Veel plezier!
});
Flambe tries to find a pack suffixed with the closest available variant of the locale. For example, fromAssetsLocalized("foo", "pt-BR")
will first try to load "content_pt-BR", then "content_pt", then just "content".
Note, it does not mix folder content, so the localized assetpacks should all have the same amount of assets.
Documentation guide for Flambe - Targeted to version 4.0+
Flambe | Installation | Demo projects | Showcase | API Reference | Forum
Flambe is MIT licensed and available for free. Feel free to contribute!
- Home / Installation
- Entity / Components
- Core
- Assets
- Publish your game
- Other
- Editors
- Plugins, tools, extensions
- Help
- More Flambe