Attention
You are reading the latest
(unstable) version of this documentation, which may document features not available
or compatible with Godot 3.x.
Checking the stable version of the documentation...
Work in progress
Godot documentation is being updated to reflect the latest changes in version
4.0
. Some documentation pages may
still state outdated information. This banner will tell you if you're reading one of such pages.
The contents of this page can be outdated. If you know how to improve this page or you can confirm that it's up to date, feel free to open a pull request.
HTML5 shell class reference¶
Projects exported for the Web expose the 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.
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.
Static Methods¶
Promise |
|
void |
|
boolean |
|
Instance Methods¶
Promise |
|
Promise |
|
Promise |
|
Promise |
|
void |
|
void |
|
- class Engine(initConfig)¶
Create a new Engine instance with the given configuration.
- Arguments
initConfig (
EngineConfig()
) -- The initial config for this instance.
Static Methods
- Engine.load(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.
This method will be called automatically depending on the configuration. See
unloadAfterInit
.
- Engine.isWebGLAvailable([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
- Engine.prototype.init([basePath])¶
Initialize the engine instance. Optionally, pass the base path to the engine to load it, if it hasn't been loaded yet. See
Engine.load()
.- Arguments
basePath (
string()
) -- Base path of the engine to load.
- Returns
A
Promise
that resolves once the engine is loaded and initialized.- Return type
Promise
- Engine.prototype.preloadFile(file[, path])¶
Load a file so it is available in the instance's file system once it runs. Must be called before starting the instance.
If not provided, the
path
is derived from the URL of the loaded file.- Arguments
file (
string|ArrayBuffer()
) --The file to preload.
If a
string
the file will be loaded from that path.If an
ArrayBuffer
or 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, iffile
is not a string.
- Returns
A Promise that resolves once the file is loaded.
- Return type
Promise
- Engine.prototype.start(override)¶
Start the engine instance using the given override configuration (if any).
startGame
can be used in typical cases instead.This will initialize the instance if it is not initialized. For manual initialization, see
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
- Engine.prototype.startGame(override)¶
Start the game instance using the given configuration override (if any).
This will initialize the instance if it is not initialized. For manual initialization, see
init
.This will load the engine if it is not loaded, and preload the main pck.
This method expects the initial config (or the override) to have both the
executable
andmainPack
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
- Engine.prototype.copyToFS(path, buffer)¶
Create a file at the specified
path
with the passed asbuffer
in 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¶
type |
name |
boolean |
|
HTMLCanvasElement |
|
string |
|
string |
|
string |
|
number |
|
Array.<string> |
|
function |
|
function |
|
function |
|
function |