-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
55 lines (43 loc) · 1.46 KB
/
index.js
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
import {
audio,
loader,
state,
device,
video,
utils,
plugin,
pool
} from "melonjs";
import "./index.css";
import TitleScreen from "./js/stage/title.js";
import PlayScreen from "./js/stage/play.js";
import PlayerEntity from "./js/renderables/player.js";
import DataManifest from "./manifest.js";
device.onReady(() => {
// initialize the display canvas once the device/browser is ready
if (!video.init(1218, 562, { parent: "screen", scale: "auto" })) {
alert("Your browser does not support HTML5 canvas.");
return;
}
// initialize the debug plugin in development mode.
if (process.env.NODE_ENV === 'development') {
import("@melonjs/debug-plugin").then((debugPlugin) => {
// automatically register the debug panel
utils.function.defer(plugin.register, this, debugPlugin.DebugPanelPlugin, "debugPanel");
});
}
// Initialize the audio.
audio.init("mp3,ogg");
// allow cross-origin for image/texture loading
loader.setOptions({crossOrigin: "anonymous"});
// set and load all resources.
loader.preload(DataManifest, function () {
// set the user defined game stages
state.set(state.MENU, new TitleScreen());
state.set(state.PLAY, new PlayScreen());
// add our player entity in the entity pool
pool.register("mainPlayer", PlayerEntity);
// Start the game.
state.change(state.PLAY);
});
});