Skip to content

Commit 5af16da

Browse files
committed
Implement fullscreen
1 parent a71e743 commit 5af16da

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

raylib.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class RaylibJs {
3434
#reset() {
3535
this.previous = undefined;
3636
this.wasm = undefined;
37+
this.htmlCanvasElement = undefined;
3738
this.ctx = undefined;
3839
this.dt = undefined;
3940
this.targetFPS = 60;
@@ -60,8 +61,8 @@ class RaylibJs {
6061
return;
6162
}
6263

63-
const canvas = document.getElementById(canvasId);
64-
this.ctx = canvas.getContext("2d");
64+
this.htmlCanvasElement = document.getElementById(canvasId);
65+
this.ctx = this.htmlCanvasElement.getContext("2d");
6566
if (this.ctx === null) {
6667
throw new Error("Could not create 2d canvas context");
6768
}
@@ -117,6 +118,18 @@ class RaylibJs {
117118
return false;
118119
}
119120

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

0 commit comments

Comments
 (0)