create-pixifact 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import './styles.css';
|
|
2
2
|
import 'pixifact:scenes';
|
|
3
3
|
import { Application } from 'pixi.js';
|
|
4
|
+
import type { PixifactProjectConfig } from 'pixifact';
|
|
5
|
+
import { applyPixifactViewportLayout, calculatePixifactViewportLayout } from 'pixifact/runtime';
|
|
6
|
+
import projectConfigJson from '../pixifact.project.json';
|
|
4
7
|
import { MainMenu } from './scenes/MainMenu';
|
|
5
8
|
|
|
6
9
|
const root = document.querySelector<HTMLElement>('#game');
|
|
@@ -8,15 +11,40 @@ if (!root) {
|
|
|
8
11
|
throw new Error('Missing #game root.');
|
|
9
12
|
}
|
|
10
13
|
|
|
14
|
+
const gameRoot = root;
|
|
15
|
+
const projectConfig = projectConfigJson as PixifactProjectConfig;
|
|
16
|
+
const screen = gameRoot.getBoundingClientRect();
|
|
11
17
|
const app = new Application();
|
|
12
18
|
await app.init({
|
|
13
|
-
width:
|
|
14
|
-
height:
|
|
19
|
+
width: screen.width,
|
|
20
|
+
height: screen.height,
|
|
15
21
|
backgroundColor: 0x10131d,
|
|
16
22
|
antialias: true,
|
|
17
23
|
autoDensity: true,
|
|
18
24
|
resolution: Math.min(window.devicePixelRatio || 1, 2),
|
|
19
25
|
});
|
|
20
|
-
root.append(app.canvas);
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
const scene = new MainMenu();
|
|
28
|
+
|
|
29
|
+
function resizeViewport() {
|
|
30
|
+
const nextScreen = gameRoot.getBoundingClientRect();
|
|
31
|
+
app.renderer.resize(nextScreen.width, nextScreen.height);
|
|
32
|
+
applyPixifactViewportLayout({
|
|
33
|
+
root: scene,
|
|
34
|
+
stage: app.stage,
|
|
35
|
+
}, calculatePixifactViewportLayout({
|
|
36
|
+
resolution: projectConfig.resolution,
|
|
37
|
+
screen: {
|
|
38
|
+
width: nextScreen.width,
|
|
39
|
+
height: nextScreen.height,
|
|
40
|
+
},
|
|
41
|
+
mode: projectConfig.viewport.mode,
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
gameRoot.append(app.canvas);
|
|
46
|
+
app.stage.addChild(scene);
|
|
47
|
+
resizeViewport();
|
|
48
|
+
|
|
49
|
+
const resizeObserver = new ResizeObserver(resizeViewport);
|
|
50
|
+
resizeObserver.observe(gameRoot);
|