Toggle fullscreen

We can switch fullscreen on or off, but how to toggle them with single key? Like

F12 is pressed  | toggle fullscreen

Easy, very easy:

As GDevelop hasn’t the condition “If fullscreen mode = True” you’ll have to create a variable (I’ll call it fullscreen) to keep track the fullscreen mode, and you’ll need a helper variable to avoid run both sub-events immediately (activate fullscreen >> deactivate fullscreen.

EDIT: Updated post and dead image link

1 Like

Thanks!

Hi i am very frustrated about this. I did as you explained but wont work. I created the first event and tested it. the variable changed succesfully to 1. but creating the second event makes the variable to stay always to 0. please help

fullscreen_mode initial value is 0

1 conditions: global variable fullscreen_mode is =0 , F12 key is pressed
actions: do =1 to global variable fullscreen_mode, activate fullscreen: yes (keep aspect ratio: )

2 conditions: global variable fullscreen_mode is =1, F12 key is pressed
actions: do =0 to global variable fullscreen_mode, activate fullscreen: no (keep aspect ratio: )

I also tried: “if all of these conditions are true” for each event. do i do something wrong or is this a bug or something??

The fullscreen doesn’t work in preview (so as you can still see GDevelop and use the debugger). But when the game is compiled, it should work.

thanks for the quick reply. Unfortunately it wont work either compiled . it succeeds to change to fullscreen and then it wont change again in windowed mode. well sometimes works but it freezes at fullscreen and i have to restart pc. (i use LInux)

I understand your problem. This is because the first event change the “fullscreen_mode” variable to 1 and then the second event’s conditions are fulfilled (because the variable is =1). To avoid that, you to add a supplementary variable, called “firstEventAlreadyCalled” for example that you put to 0 in an event just before. Then, you set it to 1 in the first event and you test if it’s =0 in the second. So, the second event will not be executed if the first was executed.

Ahhh, the old “else”, I would like to know how my example worked 3 years ago (I’m sure I tested it, I took a screenshot) :confused:

very helpful and logical!! thanks. i tried it. but it wont work always. :confused:

Can we see your events ?

i think i messed up here!! :confused:

You need to add a “Trigger once” condition (in “Advanced” category) so as the event will be executed one time per “F12” key pressed (add it to the two events).

oh!! that did the job. thank you!! these are the final events:
this also worked!:

correction : 2nd main event 1st action should be “activate fullscreen: No”

Good work! :smiley:
I have a screenshot of a working example here, cleaning a bit your code, I’ll update my first post with this image too:


Even I think the condition “Variable fullscreen is = 1” in the event 1.2 is not required, but looks better :slight_smile:

1 Like