HTML5 shell class reference
===========================
Projects exported for the Web expose the :js:class:`Engine` class to the JavaScript environment, that allows
fine control over the engine's start-up process.
This API is built in an asynchronous manner and requires basic understanding
of `Promises ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises )`.
Engine
------
The `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 ( doc_customizing_html5_shell )`.
Static Methods
^^^^^^^^^^^^^^
+---------+-----------------------------------------------------------------------------------------------+
| Promise | :js:attr:`load | :js:attr:`args` |
+-------------------+-------------------------------+
| function | :js:attr:`onExecute` |
+-------------------+-------------------------------+
| function | :js:attr:`onExit` |
+-------------------+-------------------------------+
| function | :js:attr:`onProgress` |
+-------------------+-------------------------------+
| function | :js:attr:`onPrint` |
+-------------------+-------------------------------+
| function | :js:attr:`onPrintError` |
+-------------------+-------------------------------+
.. js:attribute:: 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**
.. js:attribute:: unloadAfterInit
Whether the unload the engine automatically after the instance is initialized.
:type: boolean
:value: `true`
.. js:attribute:: canvas
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: `null`
.. js:attribute:: executable
The name of the WASM file without the extension. (Set by Godot Editor export process).
:type: string
:value: `""`
.. js:attribute:: mainPack
An alternative name for the game pck to load. The executable name is used otherwise.
:type: string
:value: `null`
.. js:attribute:: locale
Specify a language code to select the proper localization for the game.
The browser locale will be used if none is specified. See complete list of
`supported locales ( doc_locales )`.
:type: string
:value: `null`
.. js:attribute:: canvasResizePolicy
The canvas resize policy determines how the canvas should be resized by Godot.
`0` means Godot won't do any resizing. This is useful if you want to control the canvas size from
javascript code in your template.
`1` means Godot will resize the canvas on start, and when changing window size via engine functions.
`2` means Godot will adapt the canvas size to match the whole browser window.
:type: number
:value: `2`
.. js:attribute:: args
The arguments to be passed as command line arguments on startup.
See `command line tutorial ( doc_command_line_tutorial )`.
**Note**: :js:meth:`startGame
:value: `[]`
.. js:function:: onExecute( path, args )
A callback function for handling Godot's `OS.execute` calls.
This is for example used in the Web Editor template to switch between project manager and editor, and for running the game.
:param string path:
The path that Godot's wants executed.
:param Array. args:
The arguments of the "command" to execute.
.. js:function:: onExit( 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.
:param number status_code:
The status code returned by Godot on exit.
.. js:function:: onProgress( current, total )
A callback function for displaying download progress.
The function is called once per frame while downloading files, so the usage of `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)
:param number current:
The current amount of downloaded bytes so far.
:param number total:
The total amount of bytes to be downloaded.
.. js:function:: onPrint( [ ...var_args ] )
A callback function for handling the standard output stream. This method should usually only be used in debug pages.
By default, `console.log()` is used.
:param * var_args:
A variadic number of arguments to be printed.
.. js:function:: onPrintError( [ ...var_args ] )
A callback function for handling the standard error stream. This method should usually only be used in debug pages.
By default, `console.error()` is used.
:param * var_args:
A variadic number of arguments to be printed as errors.