[SOLVED] How do I navigate the browser?

GDevelop games can be executed in browsers and I just love that stuff. It makes them just so accessible for other people.

Now imagine I want to create not just one game but several and put them on my website. For users to easily find the games I then would create some index HTML page with links to the games and the user can start them.

Let’s say after some time the user wants to change the game and thus come back to the overview page. How would I from within the game create an Action that tells the browser to go back to the index HTML page?

And now imagine I allow all the navigation via gamepads. Then going back to the index page would be ok but after that the user were forced to use mouse/keyboard/touch to activate the next game. So how about instead of creating an index page, I would create another game that just allows the player to run the game he wants to play.

For both use cases all I need is some action that allows me to point the browser to some other page…

Make the first scene of your project be that main menu (index page), and each game be one or several scenes.
This is what I did with my first project.

There’s also a “open URL” action, if you prefer.

Putting all games into one project is not what I like. I prefer independent projects that can be assembled dynamically.

But the ‘open URL’ action seems what I need. How do I use that?

Ok, it took me some time to figure out that there is an action in “Files” that is called “Open a URL or a file”. It is commented as “This action launches the specified file or URL, in a browser (or in a new tab if the game is using the Web platform and is launched inside a browser”.

I tested it briefly and I saw the described action happening. But as I mentioned above, I’d like to move the existing browser window to the new game, not open a new tab. But it was close!

In that case, I guess you will need to handle things outside of GDevelop, on the website side.
see Using the Gamepad API - Web APIs | MDN

By playing around (and developing a second game) I all of a sudden understood how the JavaScript event can be used. While in the beginning I thought ‘what use is some javascript event that is executed unconditionally’ I had to understand that

  1. I have the power to program my own if statements
  2. I can use the JavaScript event as subevent, after some condition has already evaluated.

So I use a sequence of two events now to exit my game:

<if gamepad back button is pressed> (replace with other conditions if you prefer)
    JavaScript: window.open("…/", “_self”)
    Quit the game

While the second line would terminate a locally running application, in a web application it would not work. However in a web application the javascript event will load the parent URL in the very same browser tab and thus terminate the game - anything after that will not get executed.

I will use this pattern to exit my games and return to a menu.
Now if I use a meta game as menu, it can contain similar javascript events to start the different games. With that I will be able to navigate through all the games, play them and return to the menu with whatever input device I prefer.

Ultimately that should allow me to install a Raspberry to load X, a web browser in fullscreen with start page being the menu game, and it should be a decent game console that can be extended as I go…

1 Like