Skip to content

Commit fdfbab2

Browse files
committed
Implement fullscreen
1 parent a71e743 commit fdfbab2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

raylib.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class RaylibJs {
6060
return;
6161
}
6262

63-
const canvas = document.getElementById(canvasId);
63+
let canvas = document.getElementById(canvasId);
6464
this.ctx = canvas.getContext("2d");
6565
if (this.ctx === null) {
6666
throw new Error("Could not create 2d canvas context");
@@ -117,6 +117,18 @@ class RaylibJs {
117117
return false;
118118
}
119119

120+
IsWindowFullscreen() {
121+
return document.fullscreenElement && document.fullscreenElement === this.ctx.canvas;
122+
}
123+
124+
ToggleFullscreen() {
125+
if (this.IsWindowFullscreen()) {
126+
document.exitFullscreen()
127+
} else {
128+
this.ctx.canvas.requestFullscreen();
129+
}
130+
}
131+
120132
SetTargetFPS(fps) {
121133
console.log(`The game wants to run at ${fps} FPS, but in Web we gonna just ignore it.`);
122134
this.targetFPS = fps;

0 commit comments

Comments
 (0)