Advertisement
YellowAfterlife

Preloader background in OpenFL-bitfive

Nov 4th, 2013
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.05 KB | None | 0 0
  1. package ;
  2. import flash.display.Bitmap;
  3. import flash.display.BitmapData;
  4.  
  5. /**
  6.  * Working preloader background example for openfl-bitfive
  7.  * Resource "etc/preloader.png" should be defined before all other assets in application.xml:
  8.  * <assets path="assets/etc" rename="etc" include="preloader.png" />
  9.  *
  10.  * @author YellowAfterlife
  11.  */
  12. class Preloader extends NMEPreloader {
  13.     /// Background image element
  14.     var _background:Bitmap;
  15.     /// Whether background was successfully painted.
  16.     var _painted:Bool = false;
  17.    
  18.     public function new() {
  19.         super();
  20.         _background = new Bitmap(new BitmapData(Std.int(getWidth()), Std.int(getHeight()), true, 0));
  21.         addChildAt(_background, 0);
  22.     }
  23.    
  24.     override public function onUpdate(filesLoaded:Int, filesTotal:Int):Void {
  25.         super.onUpdate(filesLoaded, filesTotal);
  26.         if (!_painted) {
  27.             try { // attempt to draw the preloader background:
  28.                 _background.bitmapData.draw(openfl.Assets.getBitmapData("etc/preloader.png"));
  29.                 _painted = true;
  30.             } catch (z:Dynamic) {
  31.                 // likely not loaded yet
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement