-
Notifications
You must be signed in to change notification settings - Fork 0
/
loading-scene.ts
65 lines (51 loc) · 1.77 KB
/
loading-scene.ts
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
import { Actor, Color, Engine, ExcaliburGraphicsContext, ImageSource, Loader, Scene, vec } from "excalibur";
import { AsyncScene } from "./scene-router";
// import to satisfy parcel
import swordUrl from './sword.png'
export class LoadingScene extends Scene implements AsyncScene {
isAsyncInitialized: boolean = false;
loader: Loader;
resources = {
playerImage: new ImageSource(swordUrl),
}
constructor() {
super();
this.loader = new Loader([
this.resources.playerImage,
]);
this.loader.loadingBarColor = Color.White;
this.loader.backgroundColor = Color.Black.toHex();
// this.loader.loadingBarPosition = vec(40, 270);
this.loader.playButtonText = 'Let\'s Go!';
this.loader.suppressPlayButton = true;
}
onPostDraw(ctx: ExcaliburGraphicsContext) {
if (!this.loader.isLoaded()) {
this.loader.canvas.draw(ctx, 0, 0);
}
}
async onAsyncInitialize(engine: Engine) {
console.log("async init load started");
// Optionally hook into the post to draw the loader
engine.onPostDraw = (ctx) => this.onPostDraw(ctx);
// Tell the loader about the engine
this.loader.wireEngine(engine);
await this.loader.load();
const actor = new Actor({
width: 100,
height: 100
});
actor.graphics.use(this.resources.playerImage.toSprite());
this.add(actor);
console.log("async init load complete");
}
onInitialize() {
console.log("sync init started");
this.camera.pos = vec(0, 0);
console.log("sync init complete");
}
onActivate() {
console.log("sync activate started");
console.log("sync activate complete");
}
}