Référence de classe shell HTML5¶
Projects exported for the Web expose the Engine()
class to the JavaScript environment, that allows
fine control over the engine's start-up process.
Cette API est construite de manière asynchrone et nécessite une compréhension de base des Promises.
Engine¶
La classe Engine
fournit des méthodes pour charger et démarrer des projets exportés sur le Web. Pour les paramètres d'exportation par défaut, elle fait déjà partie de la page HTML exportée. Pour comprendre l'utilisation pratique de la classe Engine
, voir Custom HTML page for Web export.
Méthodes statiques¶
Promesse |
|
vide |
|
booléen |
|
Méthodes d'instance¶
Promesse |
|
Promesse |
|
Promesse |
|
Promesse |
|
vide |
|
vide |
|
-
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)¶ Charge le moteur à partir du chemin de base spécifiée.
- Arguments
basePath (string) -- Chemin de base du moteur à charger.
- Renvoie
A Promise that resolves once the engine is loaded.
- Type renvoyé
Promesse
-
Engine.
unload
()¶ Déchargez le moteur pour libérer de la mémoire.
This method will be called automatically depending on the configuration. See
unloadAfterInit
.
-
Engine.
isWebGLAvailable
([majorVersion=1])¶ Vérifie si WebGL est disponible. Si nécessaire, indiquez une version particulière de WebGL à vérifier.
- Arguments
majorVersion (number) -- The major WebGL version to check for.
- Renvoie
If the given major version of WebGL is available.
- Type renvoyé
booléen
Instance Methods
-
Engine.prototype.
init
([basePath])¶ Initialisez l'instance du moteur. Si vous le souhaitez, passez le chemin de base au moteur pour le charger, s'il n'a pas encore été chargé. Voir la méthode
Engine.load()
.- Arguments
basePath (string) -- Chemin de base du moteur à charger.
- Renvoie
A
Promise
that resolves once the engine is loaded and initialized.- Type renvoyé
Promesse
-
Engine.prototype.
preloadFile
(file[, path])¶ Chargez un fichier pour qu'il soit disponible dans le système de fichiers une fois l'instance lancée. Doit être appelé avant de démarrer l'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, if
file
is not a string.
- Renvoie
A Promise that resolves once the file is loaded.
- Type renvoyé
Promesse
-
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.
- Renvoie
Promesse qui se résout une fois le moteur démarré.
- Type renvoyé
Promesse
-
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.
- Renvoie
Promesse qui se résout une fois le jeu démarré.
- Type renvoyé
Promesse
-
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 |
booléen |
|
HTMLCanvasElement |
|
chaîne |
|
chaîne |
|
chaîne |
|
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
booléen
- Value
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
- Value
null
-
executable
¶ The name of the WASM file without the extension. (Set by Godot Editor export process).
- Type
chaîne
- Value
""
-
mainPack
¶ An alternative name for the game pck to load. The executable name is used otherwise.
- Type
chaîne
- Value
null
-
locale
¶ Indiquez un code de langue pour sélectionner la localisation appropriée pour le jeu.
The browser locale will be used if none is specified. See complete list of supported locales.
- Type
chaîne
- Value
null
-
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
-
args
¶ The arguments to be passed as command line arguments on startup.
Note:
startGame
will always add the--main-pack
argument.- Type
Array.<string>
- Value
[]
-
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.
- Arguments
path (string) -- The path that Godot's wants executed.
args (Array.<string>) -- 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.
- Arguments
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.Si la fonction de rappel reçoit une quantité totale de bytes de 0, ça signifie que le calcul est impossible, les raisons possibles peuvent être les suivantes :
Les fichiers sont délivrés avec une compression par tronçons réalisée par le serveur
Les fichiers sont délivrés avec une compression côté serveur sur Chromium
Les téléchargements de fichiers n'ont pas encore tous démarré (en général sur des serveurs sans multi-threading)
- Arguments
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.
Par défaut,
console.log()`
est utilisé.- Arguments
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.- Arguments
var_args (*) -- A variadic number of arguments to be printed as errors.
-