Work in progress
The content of this page was not yet updated for Godot
4.4
and may 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 |
|
インタンス メソッド
Promise |
|
Promise |
|
Promise |
|
Promise |
|
void |
|
void |
|
- class Engine(initConfig)
Create a new Engine instance with the given configuration.
- 引数:
initConfig (
EngineConfig()) -- The initial config for this instance.
Static Methods
- Engine.load(basePath)
Load the engine from the specified base path.
- 引数:
basePath (
string()) -- ロードするエンジンのベースパス。
- 戻り値:
A Promise that resolves once the engine is loaded.
- 戻り値の型:
Promise
- Engine.unload()
エンジンをアンロードしてメモリを解放します。
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.
- 引数:
majorVersion (
number()) -- The major WebGL version to check for.
- 戻り値:
If the given major version of WebGL is available.
- 戻り値の型:
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().- 引数:
basePath (
string()) -- ロードするエンジンのベースパス。
- 戻り値:
A
Promisethat resolves once the engine is loaded and initialized.- 戻り値の型:
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
pathis derived from the URL of the loaded file.- 引数:
file (
string|ArrayBuffer()) --ファイルのプリロード(事前読み込み)。
If a
stringthe file will be loaded from that path.If an
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.
- 戻り値:
A Promise that resolves once the file is loaded.
- 戻り値の型:
Promise
- Engine.prototype.start(override)
Start the engine instance using the given override configuration (if any).
startGamecan 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.
- 引数:
override (
EngineConfig()) -- An optional configuration override.
- 戻り値:
エンジンが起動すると得られるPromise。
- 戻り値の型:
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
executableandmainPackproperties set (normally done by the editor during export).- 引数:
override (
EngineConfig()) -- An optional configuration override.
- 戻り値:
ゲームが開始すると得られるPromise。
- 戻り値の型:
Promise
- Engine.prototype.copyToFS(path, buffer)
Create a file at the specified
pathwith the passed asbufferin the instance's file system.- 引数:
path (
string()) -- The location where the file will be created.buffer (
ArrayBuffer()) -- ファイルの内容。
- 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.
プロパティ
type |
name |
boolean |
|
HTMLCanvasElement |
|
string |
|
string |
|
string |
|
number |
|
Array.<string> |
|
function |
|
function |
|
function |
|
function |
|
function |
- 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
- 値:
true
- 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
- 値:
null
- executable
The name of the WASM file without the extension. (Set by Godot Editor export process).
- Type:
string
- 値:
""
- mainPack
An alternative name for the game pck to load. The executable name is used otherwise.
- Type:
string
- 値:
null
- 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.
- Type:
string
- 値:
null
- canvasResizePolicy
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
- 値:
2
- args
The arguments to be passed as command line arguments on startup.
Note:
startGamewill always add the--main-packargument.- Type:
Array.<string>
- 値:
[]
- onExecute(path, args)
A callback function for handling Godot's
OS.executecalls.This is for example used in the Web Editor template to switch between Project Manager and editor, and for running the game.
- 引数:
path (
string()) -- The path that Godot's wants executed.args (
Array.) -- The arguments of the "command" to execute.
- 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.
- 引数:
status_code (
number()) -- The status code returned by Godot on exit.
- 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:
ファイルは、サーバー側のチャンク圧縮で配信されます
ファイルはChromium上のサーバー側の圧縮で配信されます
すべてのファイルのダウンロードがまだ開始されていません(通常はマルチスレッドを使用しないサーバー)
- 引数:
current (
number()) -- The current amount of downloaded bytes so far.total (
number()) -- The total amount of bytes to be downloaded.
- onPrint([...var_args])
A callback function for handling the standard output stream. This method should usually only be used in debug pages.
デフォルトでは
console.log()が使用されます。- 引数:
var_args (
*()) -- A variadic number of arguments to be printed.
- 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.- 引数:
var_args (
*()) -- A variadic number of arguments to be printed as errors.