Exit fullscreen mode for this application.
Returns true if the browser/device is currently in fullscreen mode.
Thin convenience around device.isFullscreen so the
fullscreen trio (isFullscreen / requestFullscreen /
exitFullscreen) lives together on the app instance.
Trigger a fullscreen request for this application. Defaults to this
application's parentElement (the container the canvas was appended
into — see Application#getParentElement), so the canvas and
any sibling HUD / overlay markup inside that container go fullscreen
together.
Optionalelement: Element
optional element to fullscreen instead of this.parentElement
Create a new melonJS Application.
Constructing the instance is only the first half of starting a game:
you MUST then call (and await) init to
build the renderer — an Application on which init() has not resolved
has no renderer, no canvas, and cannot render anything.
The width of the canvas viewport
The height of the canvas viewport
The optional parameters for the application and default renderer
true when this app instance has been initialized
Last time the game update loop was executed.
Use this value to implement frame prediction in drawing events,
for creating smooth motion while running game update logic at
a lower fps.
Measured wall-clock cost of the most recent logic step, in ms
(performance.now() taken either side of the world/stage update).
Used by the fixed-timestep loop to avoid a spiral of death: the accumulator drains by at least this much, so a scene too heavy to simulate in real time slows down instead of locking up.
Only the last step of a frame is recorded, so a frame that ran several
catch-up steps reports less than its total update cost.
Renamed from updateAverageDelta in 20.0.0.
when true, all objects will be added under the root world container.
When false, a me.Container object will be created for each corresponding groups
the parent HTML element holding the main canvas of this application
Specify whether to pause this app when losing focus
a reference to the active Canvas, WebGL or (experimental) WebGPU renderer
Specify whether to unpause this app when gaining back focus
the given settings used when creating this application
Specify whether to stop this app when losing focus
Simulated time advanced by one logic step, in ms — what world.update()
receives. Fixed at 1000 / world.fps unless timer.interpolation is on,
in which case it follows the real frame delta.
Not to be confused with Application#lastUpdateDelta, which is how long that step actually took to compute.
the active stage "default" camera
a reference to the game world,
a world is a virtual environment containing all the game objects
since 20.0.0 — renamed to Application#lastUpdateDelta. The old name claimed an average that has not existed since 2015, when the exponential smoothing behind it was removed a day after being added.
Destroy this application instance and release all associated resources. Removes the canvas from the DOM, destroys the world, and unregisters all event listeners.
Terminal: a destroyed Application cannot be re-initialized —
init() rejects afterwards (and an init() still in flight aborts).
Construct a new Application to start again.
if true, the canvas element is removed from the DOM (default: true)
draw the active scene/stage associated to this game
Freeze the current stage for a fixed duration, then automatically resume. Useful for hit-stop / hit-pause effects on impact.
Convenience proxy for state.freeze; see that method's
documentation for the full behaviour matrix (extend-not-stack semantics,
interaction with manual state.pause() / state.resume(), automatic
cancellation on window blur, etc.).
duration of the freeze in milliseconds
Optionalmusic: boolean = false
also pause the current music track during the freeze
a Promise that resolves once the freeze ends (or is cancelled)
Returns the parent HTML Element holding the main canvas of this application
the parent HTML element
Build the renderer and everything that depends on it — the canvas (appended to the parent element), the initial resize layout, and the console banner. Reads Application#settings, resolved by the constructor; it takes no arguments of its own.
Calling and awaiting this is mandatory — it is the second half of
every Application's start-up, not an optional step. It resolves
synchronously for the Canvas and WebGL backends, which acquire their
context without suspending — but WebGPU cannot, and an application
whose init() has not resolved has no renderer.
resolves once the application is ready to use
Pause the current stage. Convenience proxy for state.pause.
Optionalmusic: boolean = false
also pause the current music track
force the redraw (not update) of all objects
reset the game Object manager destroy all current objects
Trigger a manual resize of the application canvas to fit the parent element. This is automatically called on window resize/orientation change, but can be called manually if the parent element size changes programmatically.
Resume the current stage. Convenience proxy for state.resume.
Optionalmusic: boolean = false
also resume the current music track
update all objects related to this game active scene/stage
current timestamp as provided by the RAF callback
Update the renderer framerate using the system config variables.
The Application class is the main entry point for creating a melonJS game. The constructor resolves the given settings, creates the game world and registers DOM event listeners (resize, orientation, scroll); you MUST then call (and await) init, which builds the renderer, appends the canvas to the parent element, and starts the game loop — without it the application has no renderer and displays nothing.
The Application instance provides access to the core game systems:
The app instance is automatically passed to Stage#onResetEvent and Stage#onDestroyEvent, and is accessible from any renderable via parentApp.
Example