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,6 @@
1
1
  {
2
2
  "name": "create-pixifact",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "创建 Pixifact 游戏项目。",
5
5
  "packageManager": "bun@1.3.13",
6
6
  "type": "module",
@@ -10,10 +10,10 @@
10
10
  },
11
11
  "dependencies": {
12
12
  "pixi.js": "8.18.1",
13
- "pixifact": "^0.2.1"
13
+ "pixifact": "^0.2.2"
14
14
  },
15
15
  "devDependencies": {
16
- "pixifact-cli": "^0.2.1",
16
+ "pixifact-cli": "^0.2.2",
17
17
  "typescript": "^5.3.3",
18
18
  "vite": "^8.0.10"
19
19
  }
@@ -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: 960,
14
- height: 540,
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
- app.stage.addChild(new MainMenu());
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);
@@ -11,6 +11,10 @@ body {
11
11
  background: #10131d;
12
12
  }
13
13
 
14
+ #game {
15
+ overflow: hidden;
16
+ }
17
+
14
18
  canvas {
15
19
  display: block;
16
20
  }
@@ -6,6 +6,8 @@
6
6
  "strict": true,
7
7
  "experimentalDecorators": true,
8
8
  "useDefineForClassFields": true,
9
+ "resolveJsonModule": true,
10
+ "allowSyntheticDefaultImports": true,
9
11
  "lib": ["ESNext", "DOM"],
10
12
  "skipLibCheck": true
11
13
  },