Last active
October 12, 2015 12:08
-
-
Save alamboley/4024623 to your computer and use it in GitHub Desktop.
How to make a preloader (Citrus Engine recipe)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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