Skip to content

Commit 097b2f0

Browse files
committed
Resize canvas based on container size
1 parent ddb3a0c commit 097b2f0

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

.github/workflows/github-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Release to Github Pages
33

44
on:
55
push:
6-
branches: [main]
6+
branches: [main, add-wasm-backend]
77
paths:
88
- 'examples/wasm/**'
99
workflow_dispatch:

examples/wasm/game.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Configuration constants
22
const CONFIG = {
33
GROUND_HEIGHT: 22,
4+
CANVAS: {
5+
WIDTH: 600,
6+
HEIGHT: 300,
7+
},
48
PLAYER: {
59
WIDTH: 80,
610
HEIGHT: 40,
@@ -70,6 +74,9 @@ const Utils = {
7074

7175
// Game elements
7276
const canvas = document.getElementById("game-canvas");
77+
canvas.width = CONFIG.CANVAS.WIDTH;
78+
canvas.height = CONFIG.CANVAS.HEIGHT;
79+
7380
const ctx = canvas.getContext("2d");
7481
const UI = {
7582
gameOverMessage: document.getElementById("game-over"),

examples/wasm/index.css

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,24 @@
77
font-style: normal;
88
}
99
body {
10-
display: flex;
11-
align-items: center;
12-
justify-content: center;
13-
flex-direction: column;
1410
min-height: 100vh;
1511
margin: 0;
1612
padding-top: 1.5rem;
17-
background-color: #f0f4f8; /* Soft light blue-gray */
18-
font-family: 'Silkscreen', cursive; /* Pixel font for everything */
19-
color: #334e68; /* Dark blue-gray text */
13+
background-color: #f0f4f8;
14+
font-family: 'Silkscreen', cursive;
15+
color: #334e68;
2016
}
2117
body > * {
22-
width: 600px;
23-
margin: 0 0 2rem;
18+
max-width: 600px;
19+
min-width: 400px;
20+
margin: 0 auto 2rem;
2421
}
2522
h1, h2 {
26-
font-family: 'Press Start 2P', cursive; /* Pixel font for everything */
23+
font-family: 'Press Start 2P', cursive;
2724
text-align: center;
2825
}
2926
h1 {
30-
color: #243b53; /* Darker blue-gray for title */
27+
color: #243b53;
3128
}
3229
h3 {
3330
margin-bottom: 1.5rem;
@@ -48,7 +45,7 @@ code, p {
4845
}
4946
p {
5047
font-size: 1.2em;
51-
margin: 0 0 1em;
48+
margin: 0 auto 1em;
5249
line-height: 1.3em;
5350
}
5451
p code {
@@ -59,17 +56,21 @@ code {
5956
}
6057
.game-container {
6158
position: relative;
62-
width: 600px;
63-
height: 300px;
59+
min-width: 400px;
60+
max-width: 600px;
6461
border: 4px solid #9fb3c8; /* Muted blue-gray border */
6562
box-sizing: content-box; /* Include padding and border in the element's total width and height */
63+
margin: 0 auto 2rem;
6664
}
6765
canvas {
6866
background-color: #0c0c1f; /* Dark blue night sky */
6967
image-rendering: pixelated; /* Ensure pixel art stays sharp */
7068
image-rendering: -moz-crisp-edges;
7169
image-rendering: -webkit-crisp-edges;
7270
display: block; /* Remove extra space below canvas */
71+
width: 100%;
72+
height: 100%;
73+
aspect-ratio: 600 / 300;
7374
}
7475
.socials a {
7576
float: right;

examples/wasm/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h1>
2929
</p>
3030
<h3>DEMO: Nyan Jump! (WASM Edition)</h3>
3131
<div class="game-container">
32-
<canvas id="game-canvas" width="600" height="300"></canvas>
32+
<canvas id="game-canvas" width="100%"></canvas>
3333
<div id="game-over">GAME OVER!</div>
3434
<button id="restart-button">Restart</button>
3535
<button id="share-button">Share on X</button>

0 commit comments

Comments
 (0)