2020-02-20 20:12:55 +00:00
|
|
|
import { Application, settings, SCALE_MODES, Ticker } from "pixi.js";
|
|
|
|
|
import globals from "./globals";
|
|
|
|
|
import { canvasWidth, canvasHeight } from "./constants";
|
|
|
|
|
import { loadResources } from "./resources";
|
|
|
|
|
import { setup } from "./setup";
|
2020-02-17 11:56:41 +00:00
|
|
|
|
2020-02-06 10:57:43 +00:00
|
|
|
|
|
|
|
|
// Initialize pixi
|
2020-02-19 22:07:52 +00:00
|
|
|
globals.app = new Application({
|
2020-02-06 10:57:43 +00:00
|
|
|
width: canvasWidth,
|
|
|
|
|
height: canvasHeight,
|
2020-02-20 20:12:55 +00:00
|
|
|
backgroundColor: 0x10101010,
|
2020-02-06 10:57:43 +00:00
|
|
|
resolution: 1,
|
|
|
|
|
antialias: false,
|
|
|
|
|
})
|
2020-02-19 22:07:52 +00:00
|
|
|
document.body.appendChild(globals.app.view)
|
2020-02-06 10:57:43 +00:00
|
|
|
|
|
|
|
|
settings.SCALE_MODE = SCALE_MODES.NEAREST
|
|
|
|
|
settings.ROUND_PIXELS = true
|
|
|
|
|
|
|
|
|
|
recalculateSize()
|
|
|
|
|
|
|
|
|
|
window.addEventListener( 'resize', recalculateSize, false )
|
|
|
|
|
|
|
|
|
|
function recalculateSize(){
|
|
|
|
|
let multiplier = Math.min((window.innerWidth/canvasWidth)|0, (window.innerHeight/canvasHeight)|0)
|
2020-02-19 22:07:52 +00:00
|
|
|
globals.app.view.style.width = canvasWidth * multiplier + "px"
|
|
|
|
|
globals.app.view.style.height = canvasHeight * multiplier + "px"
|
2020-02-06 10:57:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadResources(init)
|
|
|
|
|
|
|
|
|
|
function init(){
|
2020-02-17 11:56:41 +00:00
|
|
|
setup()
|
2020-02-06 10:57:43 +00:00
|
|
|
|
|
|
|
|
// Run!
|
|
|
|
|
Ticker.shared.add((delta : number) => {
|
|
|
|
|
let time = performance.now()
|
|
|
|
|
// Run all the systems
|
2020-02-19 22:07:52 +00:00
|
|
|
globals.world.execute(delta/100, time)
|
2020-02-06 10:57:43 +00:00
|
|
|
});
|
|
|
|
|
}
|