HTML5 shell class reference
Engine() class to the JavaScript environment, that allows fine control over the engine’s start-up process. Promises.
Engine
Engine class provides methods for loading and starting exported projects on the Web. For default export settings, this is already part of the exported HTML page. To understand practical use of the Engine class, see Custom HTML page for Web export.
Static Methods
Instance Methods
class Engine(initConfig) Create a new Engine instance with the given configuration.
Arguments
initConfig (EngineConfig()) — The initial config for this instance. Static Methods
basePath) Load the engine from the specified base path.
Arguments
basePath (
string()) — Base path of the engine to load.
Returns A Promise that resolves once the engine is loaded. Return type Promise
- Engine.unload() Unload the engine to free memory. unloadAfterInit.
majorVersion=1]) Check whether WebGL is available. Optionally, specify a particular version of WebGL to check for.
Arguments
majorVersion (
number()) — The major WebGL version to check for.
Returns If the given major version of WebGL is available. Return type boolean Instance Methods
basePath]) Engine.load().
Arguments
basePath (
string()) — Base path of the engine to load.
Returns
Promise that resolves once the engine is loaded and initialized.
Return type
Promise
file[, path]) before starting the instance.
pathis derived from the URL of the loaded file.Arguments
file (
string|ArrayBuffer()) — The file to preload.stringthe file will be loaded from that path.ArrayBufferor a view on one, the buffer will used as the content of the file.- path (
string()) — Path by which the file will be accessible. Required, iffileis not a string.
Returns A Promise that resolves once the file is loaded. Return type Promise
override) startGame can be used in typical cases instead. init. The engine must be loaded beforehand. Fails if a canvas cannot be found on the page, or not specified in the configuration.
Arguments
override (EngineConfig()) — An optional configuration override.
Returns Promise that resolves once the engine started. Return type Promise
override) Start the game instance using the given configuration override (if any). init. This will load the engine if it is not loaded, and preload the main pck. executable and mainPack properties set (normally done by the editor during export).
Arguments
override (EngineConfig()) — An optional configuration override.
Returns Promise that resolves once the game started. Return type Promise
path, buffer)
pathwith the passed asbufferin the instance’s file system.Arguments
path (
string()) — The location where the file will be created.- buffer (
ArrayBuffer()) — The content of the file. - Engine.prototype.requestQuit()
Request that the current instance quit.
This is akin the user pressing the close button in the window manager, and will have no effect if the engine has crashed, or is stuck in a loop.
Engine configuration
An object used to configure the Engine instance based on godot export options, and to override those in custom HTML templates if needed.Properties
EngineConfig The Engine configuration object. This is just a typedef, create it like a regular object, e.g.:const MyConfig = { executable: 'godot', unloadAfterInit: false }Property Descriptions unloadAfterInit Whether the unload the engine automatically after the instance is initialized.
Type boolean Value
truecanvas The HTML DOM Canvas object to use. By default, the first canvas element in the document will be used is none is specified.
Type HTMLCanvasElement Value
nullexecutable The name of the WASM file without the extension. (Set by Godot Editor export process).
Type string Value
""mainPack An alternative name for the game pck to load. The executable name is used otherwise.
Type string Value
nulllocale Specify a language code to select the proper localization for the game. supported locales.
Type string Value
nullcanvasResizePolicy The canvas resize policy determines how the canvas should be resized by Godot.
0means Godot won’t do any resizing. This is useful if you want to control the canvas size from javascript code in your template.1means Godot will resize the canvas on start, and when changing window size via engine functions.2means Godot will adapt the canvas size to match the whole browser window.Type number Value
2args The arguments to be passed as command line arguments on startup. command line tutorial. Note: startGame will always add the
--main-packargument.Type Array.
Value []path, args)
OS.executecalls. This is for example used in the Web Editor template to switch between project manager and editor, and for running the game.Arguments
path (
string()) — The path that Godot’s wants executed.- args (
Array.) — The arguments of the “command” to execute. status_code) A callback function for being notified when the Godot instance quits. Note: This function will not be called if the engine crashes or become unresponsive.
Arguments
status_code (
number()) — The status code returned by Godot on exit.current, total) A callback function for displaying download progress.
requestAnimationFrame()is not necessary. If the callback function receives a total amount of bytes as 0, this means that it is impossible to calculate. Possible reasons include:Files are delivered with server-side chunked compression
- Files are delivered with server-side compression on Chromium
- Not all file downloads have started yet (usually on servers without multi-threading)
Arguments
current (
number()) — The current amount of downloaded bytes so far.- total (
number()) — The total amount of bytes to be downloaded. …var_args]) A callback function for handling the standard output stream. This method should usually only be used in debug pages.
console.log()is used.Arguments
var_args (
*()) — A variadic number of arguments to be printed.…var_args]) A callback function for handling the standard error stream. This method should usually only be used in debug pages.
console.error()is used.Arguments
var_args (
*()) — A variadic number of arguments to be printed as errors.
