-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
73 lines (62 loc) · 1.47 KB
/
Copy pathindex.html
File metadata and controls
73 lines (62 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!doctype html>
<html>
<head>
<title>WebGL | Zig + Raylib</title>
<meta charset="utf-8" />
</head>
<body>
<canvas id="canvas" width="800" height="800"></canvas>
<div>
<button id="btnSetTitle">Set Title:</button>
</div>
<script type="module" async>
import createGameModule from './zig-out/lib/game.mjs'
const Mod = await createGameModule({
print: console.info,
printErr: console.error,
canvas: document.getElementById("canvas"),
});
const Game = {
init() {
Mod._game_init()
},
update() {
Mod._game_update();
},
logInfo() {
Mod._game_log_info()
},
setTitle(str) {
const len = Mod.lengthBytesUTF8(str) + 1;
const ptr = Mod.stackAlloc(len); // auto free
Mod.stringToUTF8(str, ptr, len);
Mod._game_set_title(ptr);
},
getTitle(str) {
const ptr = Mod.stackAlloc(1000); // auto free
Mod._game_get_title(ptr);
const out = Mod.UTF8ToString(ptr);
return out;
}
}
Game.logInfo()
Game.init()
function loop() {
Game.update();
requestAnimationFrame(loop);
}
loop();
window.Mod = Mod;
window.Game = Game;
const btnSetTitle = document.getElementById("btnSetTitle")
btnSetTitle.innerText = "Set Title: " + Game.getTitle();
btnSetTitle.addEventListener("click", () => {
const title = prompt("new title");
if (title) {
Game.setTitle(title)
btnSetTitle.innerText = "Set Title: " + Game.getTitle();
}
})
</script>
</body>
</html>