From fdfbab2fbab4bd296d400a3f65cae7ce5e5911a3 Mon Sep 17 00:00:00 2001 From: k00lagin Date: Tue, 7 May 2024 20:39:13 +0500 Subject: [PATCH] Implement fullscreen --- raylib.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/raylib.js b/raylib.js index a6a0154..3393dcf 100644 --- a/raylib.js +++ b/raylib.js @@ -60,7 +60,7 @@ class RaylibJs { return; } - const canvas = document.getElementById(canvasId); + let canvas = document.getElementById(canvasId); this.ctx = canvas.getContext("2d"); if (this.ctx === null) { throw new Error("Could not create 2d canvas context"); @@ -117,6 +117,18 @@ class RaylibJs { return false; } + IsWindowFullscreen() { + return document.fullscreenElement && document.fullscreenElement === this.ctx.canvas; + } + + ToggleFullscreen() { + if (this.IsWindowFullscreen()) { + document.exitFullscreen() + } else { + this.ctx.canvas.requestFullscreen(); + } + } + SetTargetFPS(fps) { console.log(`The game wants to run at ${fps} FPS, but in Web we gonna just ignore it.`); this.targetFPS = fps;