Fixed invalid device pixel ratio
This commit is contained in:
parent
4c1f0d002a
commit
d12af3eca4
@ -3,18 +3,22 @@ import GameMaster, { Globals } from './classes/Bastion';
|
|||||||
import Assets from './classes/Assets';
|
import Assets from './classes/Assets';
|
||||||
import { MainScene } from './scenes/Main';
|
import { MainScene } from './scenes/Main';
|
||||||
import { GameScene } from './scenes/Game';
|
import { GameScene } from './scenes/Game';
|
||||||
|
import { log } from './utils';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const app = new PIXI.Application();
|
const app = new PIXI.Application();
|
||||||
Globals.app = app;
|
Globals.app = app;
|
||||||
|
log('main - init()');
|
||||||
await app.init({
|
await app.init({
|
||||||
width: 1920, // Base width
|
width: 1920, // Base width
|
||||||
height: 1080, // Base height
|
height: 1080, // Base height
|
||||||
resolution: window.devicePixelRatio || 1,
|
resolution: 1,
|
||||||
autoDensity: true,
|
autoDensity: true,
|
||||||
backgroundColor: 0xffffff,
|
backgroundColor: 0xffffff,
|
||||||
sharedTicker: true,
|
sharedTicker: true,
|
||||||
});
|
});
|
||||||
|
log('main - init() complete');
|
||||||
|
|
||||||
document.body.appendChild(app.canvas);
|
document.body.appendChild(app.canvas);
|
||||||
|
|
||||||
function resize() {
|
function resize() {
|
||||||
@ -31,6 +35,7 @@ import { GameScene } from './scenes/Game';
|
|||||||
// Calculate new canvas size
|
// Calculate new canvas size
|
||||||
const gameWidth = Math.round(app.screen.width * scale);
|
const gameWidth = Math.round(app.screen.width * scale);
|
||||||
const gameHeight = Math.round(app.screen.height * scale);
|
const gameHeight = Math.round(app.screen.height * scale);
|
||||||
|
log(`main - resize(); window: ${window.innerWidth}x${window.innerHeight}}; game ${gameWidth}x${gameHeight}`);
|
||||||
|
|
||||||
// Center the canvas
|
// Center the canvas
|
||||||
const marginHorizontal = (windowWidth - gameWidth) / 2;
|
const marginHorizontal = (windowWidth - gameWidth) / 2;
|
||||||
|
3
src/utils.ts
Normal file
3
src/utils.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export function log(msg: any) {
|
||||||
|
console.log(msg);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user