/
Preloader.hx
80 lines (65 loc) · 1.95 KB
/
Preloader.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//SHOUTOUTS TO GAMEPOPPER FOR THE BALLIN TUTORIAL
//https://gamepopper.co.uk/2014/08/26/haxeflixel-making-a-custom-preloader/
package;
import flixel.FlxG;
import flixel.system.FlxBasePreloader;
import flash.display.*;
import flash.text.*;
import flash.Lib;
import flixel.text.FlxText;
import openfl.display.Sprite;
import openfl.display.BitmapData;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFormat;
@:font() class CustomFont extends Font {}
@:bitmap("assets/images/preloaderArt.png") class LogoImage extends BitmapData { }
class Preloader extends FlxBasePreloader
{
override public function new(MinDisplayTime:Float=0, ?AllowedURLs:Array<String>)
{
super(MinDisplayTime, AllowedURLs);
}
private var logo:Sprite;
var text:TextField;
private var _buffer:Sprite;
private var _bmpBar:Bitmap;
override private function create():Void
{
//#if (newgrounds)
//var newgrounds:NGio = new NGio(APIStuff.APIID, APIStuff.EncKey);
//#end
this._width = Lib.current.stage.stageWidth;
this._height = Lib.current.stage.stageHeight;
var ratio:Float = this._width / 800; //This allows us to scale assets depending on the size of the screen.
logo = new Sprite();
logo.scaleY = 0;
logo.addChild(new Bitmap(new LogoImage(0, 0))); //Sets the graphic of the sprite to a bitmap object, which uses our embedded bitmapData class
addChild(logo);
_buffer = new Sprite();
//_buffer.scaleX = _buffer.scaleY = 2;
addChild(_buffer);
_bmpBar = new Bitmap(new BitmapData(1, 14, false, 0x5f6aff));
_bmpBar.x = 4;
_bmpBar.y = _height - 17;
//_buffer.addChild(_bmpBar);
super.create();
}
override private function destroy():Void
{
if (_buffer != null)
{
removeChild(_buffer);
}
_buffer = null;
_bmpBar = null;
logo = null;
super.destroy();
}
override public function update(Percent:Float):Void
{
super.update(Percent);
logo.scaleY = Percent;
_bmpBar.scaleX = Percent * (_width - 8);
}
}