-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
39 lines (32 loc) · 988 Bytes
/
main.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
import Game from './lib/Game'
import { Spritesheet } from "./lib/Spritesheet";
import { Application, settings, SCALE_MODES } from 'pixi.js'
window.addEventListener('DOMContentLoaded', startInitialiseGame)
function removeExistingGame(): void {
const els = document.body.children
if (els.length > 0) document.body.removeChild(els.item(0) as Node)
}
function initialise(): Application {
removeExistingGame()
const app = new Application(800, 600, { backgroundColor: 0x000000 })
document.body.appendChild(app.view)
return app
}
function startInitialiseGame(): void {
settings.SCALE_MODE = SCALE_MODES.NEAREST
new Spritesheet("sprites.json")
Spritesheet.loadAndCall(() => completeInitialiseGame())
}
function completeInitialiseGame(): void {
console.log(Spritesheet.sheet)
const app = initialise()
const game = new Game(app)
game.start()
}
// @ts-ignore
if (module.hot) {
// @ts-ignore
module.hot.accept(function accept() {
startInitialiseGame()
})
}