Skip to content

Commit 26ef4be

Browse files
committed
center game once and for all
1 parent 5cd5bba commit 26ef4be

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

src/App.css

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,29 @@
5252
display: flex;
5353
flex-direction: column;
5454
align-items: center;
55+
justify-content: center;
5556
width: 100%;
5657
height: 100%;
57-
max-width: 100%;
58-
margin: 0;
59-
padding: 0;
60-
box-sizing: border-box;
61-
overflow: hidden;
62-
position: absolute;
63-
top: 0;
64-
left: 0;
65-
right: 0;
66-
bottom: 0;
6758
}
6859

69-
main {
60+
.app-main {
61+
display: flex;
62+
flex-direction: column;
63+
align-items: center;
64+
justify-content: center;
65+
gap: 1rem;
7066
width: 100%;
7167
height: 100%;
72-
flex-grow: 1;
68+
}
69+
70+
main {
7371
display: flex;
74-
justify-content: center;
72+
flex-direction: column;
7573
align-items: center;
76-
overflow: hidden;
77-
position: relative;
74+
justify-content: center;
75+
gap: 1rem;
76+
width: 100%;
77+
height: 100%;
7878
}
7979

8080
footer {
@@ -84,8 +84,8 @@ footer {
8484
}
8585

8686
.game-container {
87-
width: 100% !important;
88-
height: 100% !important;
87+
width: 640px;
88+
height: 576px;
8989
border-radius: 0;
9090
overflow: hidden;
9191
box-shadow: none;
@@ -97,6 +97,24 @@ footer {
9797
display: block;
9898
}
9999

100+
.game-root {
101+
display: flex;
102+
flex-direction: column;
103+
width: 100%;
104+
height: 100%;
105+
gap: 1rem;
106+
}
107+
108+
.game-wrapper {
109+
display: flex;
110+
align-items: center;
111+
justify-content: center;
112+
position: relative;
113+
width: 640px;
114+
height: 576px;
115+
margin: 0 auto;
116+
}
117+
100118
.game-container canvas {
101119
display: block !important;
102120
}

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Game from "./components/Game";
44
function App() {
55
return (
66
<div className="app-container">
7-
<main style={{ display: "flex", flexDirection: "column", gap: "1rem" }}>
7+
<main className="app-main">
88
<Game />
99
</main>
1010
</div>

src/components/Game.tsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,33 +114,17 @@ const Game = () => {
114114
}, []);
115115

116116
return (
117-
<div
118-
style={{
119-
display: "flex",
120-
flexDirection: "column",
121-
width: "100%",
122-
height: "100%",
123-
gap: "1rem",
124-
}}
125-
>
117+
<div className="game-root">
126118
<ConnectDevice
127119
onConnect={onDeviceConnect}
128120
onDisconnect={onDeviceDisconnect}
129121
device={device}
130122
/>
131-
<div
132-
style={{
133-
width: "100%",
134-
height: "100%",
135-
position: "relative",
136-
display: "flex",
137-
}}
138-
>
123+
<div className="game-wrapper">
139124
<div
140125
ref={containerRef}
141126
id="game-container"
142127
className="game-container"
143-
style={{ width: "100%", height: "100%" }}
144128
tabIndex={0}
145129
onClick={() => containerRef.current?.focus()}
146130
/>

src/game/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const gameConfig: Phaser.Types.Core.GameConfig = {
2121
scene: [MenuScene, GameScene, GameOverScene, NameEntryScene, HighScoresScene],
2222
scale: {
2323
parent: "game-container",
24+
mode: Phaser.Scale.FIT, // scale up to fit the parent
25+
autoCenter: Phaser.Scale.CENTER_BOTH, // center horizontally & vertically
26+
width: 160,
27+
height: 144,
2428
},
2529
input: {
2630
activePointers: 3,

0 commit comments

Comments
 (0)