Class: RuntimeGame

RuntimeGame

new gdjs.RuntimeGame(data, spec)

Represents a game being played.

Name Type Description
data Object

The object (usually stored in data.json) containing the full project data

spec Object optional

Optional object for specifiying additional options: {forceFullscreen: ...}

Methods

getAdaptGameResolutionAtRuntime(){boolean}

Returns if the game resolution should be automatically adapted when the game window or screen size change. This will only be the case if the game resolution resize mode is configured to adapt the width or the height of the game.

Returns:
Type Description
boolean true if the game resolution is automatically changed according to the window/screen size.

getExternalLayoutData(name){Object}

Get the data associated to an external layout.

Name Type Description
name string

The name of the external layout.

Returns:
Type Description
Object The data associated to the external layout or null if not found.

getFontManager(){gdjs.FontManager}

Get the gdjs.FontManager of the RuntimeGame.

Returns:
Type Description
gdjs.FontManager The font manager.

getGameData(){Object}

Get the object containing the game data

Returns:
Type Description
Object The object associated to the game.

getGameResolutionHeight(){number}

Get the game resolution (the size at which the game is played and rendered) height.

Returns:
Type Description
number The game resolution height, in pixels.

getGameResolutionResizeMode(){string}

Returns if the width or the height of the game resolution should be changed to fit the game window - or if the game resolution should not be updated automatically (empty string).

Returns:
Type Description
string Either "" (don't change game resolution), "adaptWidth" or "adaptHeight".

getGameResolutionWidth(){number}

Get the game resolution (the size at which the game is played and rendered) width.

Returns:
Type Description
number The game resolution width, in pixels.

getImageManager(){gdjs.ImageManager}

Get the gdjs.ImageManager of the RuntimeGame.

Returns:
Type Description
gdjs.ImageManager The image manager.

getInitialObjectsData(){Object}

Get the data representing all the global objects of the game.

Returns:
Type Description
Object The data associated to the global objects.

Get the input manager of the game, storing mouse, keyboard and touches states.

Returns:
Type Description
gdjs.InputManager The input manager owned by the game

Get the JSON manager of the game, used to load JSON from game resources.

Returns:
Type Description
gdjs.JsonManager The json manager for the game

getMinimalFramerate()

Return the minimal fps that must be guaranteed by the game (otherwise, game is slowed down).

getOriginalHeight()

Get the original height of the game, as set on the startup of the game.

This is guaranteed to never change, even if the size of the game is changed afterwards.

getOriginalWidth()

Get the original width of the game, as set on the startup of the game.

This is guaranteed to never change, even if the size of the game is changed afterwards.

getScaleMode()

Return the scale mode of the game ("linear" or "nearest").

getSceneData(sceneName){Object}

Get the data associated to a scene.

Name Type Description
sceneName string

The name of the scene. If not defined, the first scene will be returned.

Returns:
Type Description
Object The data associated to the scene.

getSoundManager(){gdjs.SoundManager}

Get the gdjs.SoundManager of the RuntimeGame.

Returns:
Type Description
gdjs.SoundManager The sound manager.

Get the variables of the RuntimeGame.

Returns:
Type Description
gdjs.VariablesContainer The global variables

hasScene(sceneName){boolean}

Check if a scene exists

Name Type Description
sceneName string optional

The name of the scene to search.

Returns:
Type Description
boolean true if the scene exists. If sceneName is undefined, true if the game has a scene.

loadAllAssets()

Load all assets, displaying progress in renderer.

onWindowInnerSizeChanged()

Called by the game renderer when the window containing the game has changed size (this can result from a resize of the window, but also other factors like a device orientation change on mobile).

pause(enable)

Set or unset the game as paused. When paused, the game won't step and will be freezed. Useful for debugging.

Name Type Description
enable boolean

true to pause the game, false to unpause

setAdaptGameResolutionAtRuntime(enable)

Set if the game resolution should be automatically adapted when the game window or screen size change. This will only be the case if the game resolution resize mode is configured to adapt the width or the height of the game.

Name Type Description
enable boolean

true to change the game resolution according to the window/screen size.

setGameResolutionResizeMode(resizeMode)

Set if the width or the height of the game resolution should be changed to fit the game window - or if the game resolution should not be updated automatically.

Name Type Description
resizeMode string

Either "" (don't change game resolution), "adaptWidth" or "adaptHeight".

setGameResolutionSize(width, height)

Change the game resolution.

Name Type Description
width number

The new width

height number

The new height

startCurrentSceneProfiler(onProfilerStopped)

Start a profiler for the currently running scene.

Name Type Description
onProfilerStopped function

Function to be called when the profiler is stopped. Will be passed the profiler as argument.

startGameLoop()

Start the game loop, to be called once assets are loaded.

stopCurrentSceneProfiler()

Stop the profiler for the currently running scene.

wasFirstSceneLoaded()

Return true if a scene was loaded, false otherwise (i.e: game not yet started).