This repository has been archived by the owner on Oct 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathPreloader.hx
77 lines (65 loc) · 2.05 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
package;
import flixel.addons.editors.ogmo.FlxOgmo3Loader.LayerData;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.system.FlxBasePreloader;
import flash.display.*;
import flash.text.*;
import flash.Lib;
import openfl.display.Sprite;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFormat;
@:bitmap("art/preloadBG.png") class LogoImage extends BitmapData
{
}
@:font("assets/fonts/vcr.ttf") class CustomFont extends Font
{
}
class Preloader extends FlxBasePreloader
{
public function new(MinDisplayTime:Float = 5, ?AllowedURLs:Array<String>)
{
super(MinDisplayTime, AllowedURLs);
}
var logo:Sprite;
var text:TextField;
override function create():Void
{
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.addChild(new Bitmap(new LogoImage(0, 0))); // Sets the graphic of the sprite to a Bitmap object, which uses our embedded BitmapData class.
logo.x = ((this._width) / 2) - ((logo.width) / 2);
logo.y = (this._height / 2) - ((logo.height) / 2);
logo.scaleX -= 0.5;
logo.scaleY -= 0.5;
addChild(logo); // Adds the graphic to the NMEPreloader's buffer.
Font.registerFont(CustomFont);
text = new TextField();
text.defaultTextFormat = new TextFormat("VCR OSD Mono", 12, 0xffffff);
text.embedFonts = true;
text.text = "Preloading assets...";
addChild(text);
super.create();
}
override function update(Percent:Float):Void
{
super.update(Percent);
text.x = Lib.current.stage.stageWidth - 10 - text.width;
text.y = Lib.current.stage.stageHeight - 10 - text.height;
switch (Percent)
{
case 50:
text.text = "Halfway there...";
case 70:
text.text = "Almost there...";
case 80:
text.text = "Done!";
case 90:
FlxTween.tween(text, {alpha: 0, y: text.y - 50}, 0.5, {ease: FlxEase.cubeInOut});
FlxTween.tween(logo, {alpha: 0, y: text.y - 50}, 0.5, {ease: FlxEase.cubeInOut});
}
}
}