-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
55 lines (43 loc) · 1.4 KB
/
main.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 { Container } from 'pixi.js-legacy'
import { gameApp, stage, loader, config } from './config/config'
import { assets } from './config/assets'
import { ScreenHandler, TitleScreen, GameScreen } from './modules/screens'
import { basicSprite } from './modules/simpleSprite'
// Adds the app canvas to the html <body>
document.body.appendChild(gameApp.view);
// Loading Screen ===============
const loadingScreen = new Container()
stage.addChild(loadingScreen)
loader.onStart.add(() => {
let load_background = basicSprite(
'./assets/loadingscreen.png',
config.gameWidth/2,
config.gameHeight/2,
config.gameWidth,
config.gameHeight)
loadingScreen.addChild(load_background)
})
// Loading Screen ===============
// Load assets and start Game
loader
.add(assets)
.load(start);
// Screen ceation and pass to handler
const titlescreen = new TitleScreen(stage)
const gamescreen = new GameScreen(stage)
// Set screens with name to be call inside each one
const screens = [
{name:'titlescreen',data:titlescreen},
{name:'gamescreen',data:gamescreen}
]
// Start Game
function start() {
loadingScreen.visible = false // Hide Loading Screen
new ScreenHandler(screens) // Set initialize handler
titlescreen.init = true // Initialize Title Screen
gameApp.ticker.add((deltaTime) => {
// Update Loop
titlescreen.update(deltaTime)
gamescreen.update(deltaTime)
});
}