Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HTML5] Easier HTML templates, better canvas size handling #46200

Merged
merged 2 commits into from Feb 19, 2021

Conversation

Faless
Copy link
Collaborator

@Faless Faless commented Feb 19, 2021

In this PR:

HTML Templates

Improving on the proposal, now the minimum JS code is just the collowing:

var engine = new Engine($GODOT_RUN_OPTIONS);
engine.startGame();

The minimal HTML example is as folowing:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
	</head>
	<body>
		<canvas id="canvas"></canvas>
		<script src="$GODOT_URL"></script>
		<script>
			var engine = new Engine($GODOT_CONFIG);
			engine.startGame();
		</script>
	</body>
</html>

You'll be able to set overrides during start and startGame phases, e.g.:

engine.startGame({
	"onExit": function (code) {
		alert("Game exited...");
	}
});

There are 2 additional tags that are recommended but optional:

  • $GODOT_HEAD_INCLUDE - the custom HTML head include.
  • $GODOT_PROJECT_NAME - for the project title (if you want to set it as the title in the page for better browser caching).

Canvas Size

The full window option is now renamed to Canvas Resize Policy and is a 3-state enum:

  • None: Godot window settings are ignored.
  • Project: Godot handles the canvas like a native app (resizing it when setting the window size).
  • Adaptive: Canvas size will always adapt to browser window size.

Use None if you want to control the canvas size with custom JavaScript code.

Both canvas resizing functions and fullscreen functions has been moved to an internal implementation.

Export window screenshot

There is a 3.2 branch that can be tested here: https://github.com/Faless/godot/tree/js/3.x_canvas_size_pr

Three canvas resize policies:
- `None`: Godot window settings are ignored.
- `Project`: Godot handles the canvas like a native app (resizing it
  when setting the window size).
- `Adaptive`: Canvas size will always adapt to browser window size.

Use `None` if you want to control the canvas size with custom JavaScript
code.
@akien-mga akien-mga merged commit 480c5f2 into godotengine:master Feb 19, 2021
@akien-mga
Copy link
Member

Thanks!

@Unradelic
Copy link

Typo on description:

...the minimum JS code is just the collowing:"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants