Skip to content

Instantly share code, notes, and snippets.

@alamboley
Last active October 12, 2015 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alamboley/4024623 to your computer and use it in GitHub Desktop.
Save alamboley/4024623 to your computer and use it in GitHub Desktop.
How to make a preloader (Citrus Engine recipe)
// Arts specified by a path to a file like "levels/coin.png" are loaded under the hood by the Citrus Engine.
//You can follow the progression in your GameState :
//add a mask to the game to hide objects loading in the background
_maskDuringLoading = new Quad(stage.stageWidth, stage.stageHeight);
addChild(_maskDuringLoading);
// create a textfield to show the loading %
_percentTF = new TextField(400, 200, "", "ArialMT");
addChild(_percentTF);
// when the loading is completed...
view.loadManager.onLoadComplete.addOnce(_handleLoadComplete);
protected function _handleLoadComplete():void {
removeChild(_percentTF, true);
removeChild(_maskDuringLoading, true);
}
override public function update(timeDelta:Number):void {
super.update(timeDelta);
var percent:uint = view.loadManager.bytesLoaded / view.loadManager.bytesTotal * 100;
if (percent < 99)
_percentTF.text = percent.toString() + "%";
}
// Note: if your views are never set up as a path to a file, the handleLoadComplete will never be called.
// If you're using Starling, we advice you to use its AssetManager to parse sprite sheets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment