-
Notifications
You must be signed in to change notification settings - Fork 0
/
Preloader.as
99 lines (74 loc) · 1.84 KB
/
Preloader.as
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package
{
import net.flashpunk.*;
import net.flashpunk.graphics.*;
import net.flashpunk.utils.*;
import flash.display.LoaderInfo;
import flash.utils.getDefinitionByName;
public class Preloader extends World
{
private var text: Text;
private var nextClassName: String;
private var mustClick: Boolean = true;
public function Preloader (_next: String)
{
nextClassName = _next;
text = new Text("0%", 320, 260, 300);
text.align = "center";
text.x = 320 - text.width * 0.5;
}
public override function update (): void
{
if (hasLoaded())
{
if (mustClick) {
if (Input.mousePressed) {
startup();
}
} else {
startup();
}
}
}
public override function render (): void
{
if (hasLoaded())
{
text.scale = 2;
text.text = "Click to start";
text.x = 320 - text.width * text.scale * 0.5;
text.y = 240 - text.height * text.scale * 0.5;
}
else
{
FP.rect.x = 68;
FP.rect.y = 228;
FP.rect.width = 504;
FP.rect.height = 24;
FP.buffer.fillRect(FP.rect, 0xFFFFFFFF);
var p:Number = (this.loaderInfo.bytesLoaded / this.loaderInfo.bytesTotal);
FP.rect.x = 70;
FP.rect.y = 230;
FP.rect.width = p * 500;
FP.rect.height = 20;
FP.buffer.fillRect(FP.rect, 0xFF000000);
text.text = int(p * 100) + "%";
}
FP.point.x = 0;
FP.point.y = 0;
text.render(FP.point, FP.zero);
}
private function hasLoaded (): Boolean {
return (FP.stage.loaderInfo.bytesLoaded >= FP.stage.loaderInfo.bytesTotal);
}
private function startup (): void
{
var mainClass:Class = getDefinitionByName(nextClassName) as Class;
FP.world = new mainClass() as World;
}
private function get loaderInfo (): LoaderInfo
{
return FP.engine.loaderInfo;
}
}
}