Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ;
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- /**
- * Working preloader background example for openfl-bitfive
- * Resource "etc/preloader.png" should be defined before all other assets in application.xml:
- * <assets path="assets/etc" rename="etc" include="preloader.png" />
- *
- * @author YellowAfterlife
- */
- class Preloader extends NMEPreloader {
- /// Background image element
- var _background:Bitmap;
- /// Whether background was successfully painted.
- var _painted:Bool = false;
- public function new() {
- super();
- _background = new Bitmap(new BitmapData(Std.int(getWidth()), Std.int(getHeight()), true, 0));
- addChildAt(_background, 0);
- }
- override public function onUpdate(filesLoaded:Int, filesTotal:Int):Void {
- super.onUpdate(filesLoaded, filesTotal);
- if (!_painted) {
- try { // attempt to draw the preloader background:
- _background.bitmapData.draw(openfl.Assets.getBitmapData("etc/preloader.png"));
- _painted = true;
- } catch (z:Dynamic) {
- // likely not loaded yet
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement