File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ class RaylibJs {
34
34
#reset( ) {
35
35
this . previous = undefined ;
36
36
this . wasm = undefined ;
37
+ this . htmlCanvasElement = undefined ;
37
38
this . ctx = undefined ;
38
39
this . dt = undefined ;
39
40
this . targetFPS = 60 ;
@@ -60,8 +61,8 @@ class RaylibJs {
60
61
return ;
61
62
}
62
63
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" ) ;
65
66
if ( this . ctx === null ) {
66
67
throw new Error ( "Could not create 2d canvas context" ) ;
67
68
}
@@ -117,6 +118,18 @@ class RaylibJs {
117
118
return false ;
118
119
}
119
120
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
+
120
133
SetTargetFPS ( fps ) {
121
134
console . log ( `The game wants to run at ${ fps } FPS, but in Web we gonna just ignore it.` ) ;
122
135
this . targetFPS = fps ;
You can’t perform that action at this time.
0 commit comments