Godot: Maximize HTML5 canvas in default HTML page

Created on 12 Jun 2017  路  12Comments  路  Source: godotengine/godot

Summary

It would be useful if there was an option on the Javascript export that would cause the game to run taking up the whole browser window instead of running in the exact resolution specified at export time.

Explanation

There are a couple reasons this feature would be useful:

  1. You could export games that would display correctly on screens of different sizes, densities, and aspect ratios. ( Assuming you designed the game correctly )
  2. It would allow you to make web applications using Godot. You would get all of the power of the Godot game engine to easily design web applications or SPA's.
enhancement html5 porting

Most helpful comment

This is already possible by maximizing the window:

OS.set_window_maximized(true)

In HTML5 export, the 'window' corresponds to the WebGL canvas.
You can also call OS.set_window_size() to resize the canvas to specific dimensions

All 12 comments

This is already possible by maximizing the window:

OS.set_window_maximized(true)

In HTML5 export, the 'window' corresponds to the WebGL canvas.
You can also call OS.set_window_size() to resize the canvas to specific dimensions

Oh cool. That's awesome. I'll try that. I do think it would still be good to have a checkbox on the export screen that would do this for you, though. That way you don't have to add any code, as little as it would be, and you don't have to know about that technique for maximizing it.

You should be able to use the web feature tag in the Project Settings by setting an override on the maximized property. This way, your project will only be maximized by default in HTML5 and not on other platforms.

@Calinou Somehow, the override did not work for me. I tried it with both the "web"
and the "HTML5" flag and put maximize=true but the game (Escape the Creeps )still did not stretch to fit the browser window.

I found that putting
if OS.get_name()=="HTML5":
OS.set_window_maximized(true)
into func _ready(): of the Main node did the job :) The game now stretches to fit the browser window but won't maximize the window of the Linux/Windows exports.

Closing as this is solved. :)

Somehow, the override did not work for me. I tried it with both the "web"
and the "HTML5" flag and put maximize=true but the game (Escape the Creeps )still did not stretch to fit the browser window.

This sounds like a bug. Perhaps this issue should be renamed and reopened, or a new issue should be opened?

Think new issue would be better for that. Who wants to do the honor? :)

There is no maximized project setting.

Sometime soon I'll change the default HTML page to maximize by default.

@eska014 You are right. There is however a property called maximize. I assumed Calinou meant that...

@zolartan Can't find a setting like that in the project settings. Maybe you added it manually for that project?

@eska014 Just checked again. Seems to be added in Godot 3.0.1. If I start the project (e.g. Escape the Creeps) with Godot 3.0 it seems to not be there. But as I said it didn't work for me anyway...

Resolved by #21336

Was this page helpful?
0 / 5 - 0 ratings