Class: Game

Phaser. Game

The Phaser.Game instance is the main controller for the entire Phaser game. It is responsible
for handling the boot process, parsing the configuration values, creating the renderer,
and setting-up all of the global Phaser systems, such as sound and input.
Once that is complete it will start the Scene Manager and then begin the main game loop.

You should generally avoid accessing any of the systems created by Game, and instead use those
made available to you via the Phaser.Scene Systems class instead.


new Game( [GameConfig])

Parameters:
Name Type Argument Description
GameConfig GameConfig <optional>

The configuration object for your Phaser Game instance.

Since: 3.0.0
Source: src/boot/Game.js (Line 38)

Members


anims :Phaser.Animations.AnimationManager

An instance of the Animation Manager.

The Animation Manager is a global system responsible for managing all animations used within your game.

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 152)

cache :Phaser.Cache.CacheManager

An instance of the Cache Manager.

The Cache Manager is a global system responsible for caching, accessing and releasing external game assets.

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 174)

canvas :HTMLCanvasElement

A reference to the HTML Canvas Element that Phaser uses to render the game.
This is created automatically by Phaser unless you provide a canvas property
in your Game Config.

Type:
  • HTMLCanvasElement
Since: 3.0.0
Source: src/boot/Game.js (Line 99)

<readonly> config :Phaser.Boot.Config

The parsed Game Configuration object.

The values stored within this object are read-only and should not be changed at run-time.

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 61)

context :CanvasRenderingContext2D|WebGLRenderingContext

A reference to the Rendering Context belonging to the Canvas Element this game is rendering to.
If the game is running under Canvas it will be a 2d Canvas Rendering Context.
If the game is running under WebGL it will be a WebGL Rendering Context.
This context is created automatically by Phaser unless you provide a context property
in your Game Config.

Type:
  • CanvasRenderingContext2D | WebGLRenderingContext
Since: 3.0.0
Source: src/boot/Game.js (Line 110)

device :Phaser.DeviceConf

A reference to the Device inspector.

Contains information about the device running this game, such as OS, browser vendor and feature support.
Used by various systems to determine capabilities and code paths.

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 216)

domContainer :HTMLDivElement

A reference to an HTML Div Element used as a DOM Element Container.

Only set if createDOMContainer is true in the game config (by default it is false) and
if you provide a parent element to insert the Phaser Game inside.

See the DOM Element Game Object for more details.

Type:
  • HTMLDivElement
Since: 3.12.0
Source: src/boot/Game.js (Line 84)

events :Phaser.Events.EventEmitter

An Event Emitter which is used to broadcast game-level events from the global systems.

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 143)

facebook :Phaser.FacebookInstantGamesPlugin

An instance of the Facebook Instant Games Plugin.

This will only be available if the plugin has been built into Phaser,
or you're using the special Facebook Instant Games custom build.

Type:
Since: 3.13.0
Source: src/boot/Game.js (Line 265)

<readonly> hasFocus :boolean

Does the window the game is running in currently have focus or not?
This is modified by the VisibilityHandler.

Type:
  • boolean
Since: 3.9.0
Source: src/boot/Game.js (Line 309)

input :Phaser.Input.InputManager

An instance of the Input Manager.

The Input Manager is a global system responsible for the capture of browser-level input events.

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 194)

<readonly> isBooted :boolean

A flag indicating when this Game instance has finished its boot process.

Type:
  • boolean
Since: 3.0.0
Source: src/boot/Game.js (Line 123)

<readonly> isOver :boolean

Is the mouse pointer currently over the game canvas or not?
This is modified by the VisibilityHandler.

Type:
  • boolean
Since: 3.10.0
Source: src/boot/Game.js (Line 320)

<readonly> isRunning :boolean

A flag indicating if this Game is currently running its game step or not.

Type:
  • boolean
Since: 3.0.0
Source: src/boot/Game.js (Line 133)

loop :Phaser.Boot.TimeStep

An instance of the Time Step.

The Time Step is a global system responsible for setting-up and responding to the browser frame events, processing
them and calculating delta values. It then automatically calls the game step.

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 239)

plugins :Phaser.Plugins.PluginManager

An instance of the Plugin Manager.

The Plugin Manager is a global system that allows plugins to register themselves with it, and can then install
those plugins into Scenes as required.

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 251)

registry :Phaser.Data.DataManager

An instance of the Data Manager

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 185)

renderer :Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer

A reference to either the Canvas or WebGL Renderer that this Game is using.

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 73)

scene :Phaser.Scenes.SceneManager

An instance of the Scene Manager.

The Scene Manager is a global system responsible for creating, modifying and updating the Scenes in your game.

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 205)

sound :Phaser.Sound.BaseSoundManager

An instance of the base Sound Manager.

The Sound Manager is a global system responsible for the playback and updating of all audio in your game.

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 228)

textures :Phaser.Textures.TextureManager

An instance of the Texture Manager.

The Texture Manager is a global system responsible for managing all textures being used by your game.

Type:
Since: 3.0.0
Source: src/boot/Game.js (Line 163)

Methods


<protected> boot()

This method is called automatically when the DOM is ready. It is responsible for creating the renderer,
displaying the Debug Header, adding the game canvas to the DOM and emitting the 'boot' event.
It listens for a 'ready' event from the base systems and once received it will call Game.start.

Since: 3.0.0
Source: src/boot/Game.js (Line 344)
Fires:

destroy(removeCanvas [, noReturn])

Flags this Game instance as needing to be destroyed on the next frame.
It will wait until the current frame has completed and then call runDestroy internally.

If you do not need to run Phaser again on the same web page you can set the noReturn argument to true and it will free-up
memory being held by the core Phaser plugins. If you do need to create another game instance on the same page, leave this as false.

Parameters:
Name Type Argument Default Description
removeCanvas boolean

Set to true if you would like the parent canvas element removed from the DOM, or false to leave it in place.

noReturn boolean <optional>
false

If true all the core Phaser plugins are destroyed. You cannot create another instance of Phaser on the same web page if you do this.

Since: 3.0.0
Source: src/boot/Game.js (Line 740)
Fires:

headlessStep(time, delta)

A special version of the Game Step for the HEADLESS renderer only.

The main Game Step. Called automatically by the Time Step, once per browser frame (typically as a result of
Request Animation Frame, or Set Timeout on very old browsers.)

The step will update the global managers first, then proceed to update each Scene in turn, via the Scene Manager.

This process emits prerender and postrender events, even though nothing actually displays.

Parameters:
Name Type Description
time number

The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.

delta number

The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.

Since: 3.2.0
Source: src/boot/Game.js (Line 565)
Fires:

<protected> onBlur()

Called automatically by the Visibility Handler.
This will set the main loop into a 'blurred' state, which pauses it.

Since: 3.0.0
Source: src/boot/Game.js (Line 658)

<protected> onFocus()

Called automatically by the Visibility Handler.
This will set the main loop into a 'focused' state, which resumes it.

Since: 3.0.0
Source: src/boot/Game.js (Line 673)

<protected> onHidden()

Called automatically by the Visibility Handler.
This will pause the main loop and then emit a pause event.

Since: 3.0.0
Source: src/boot/Game.js (Line 616)
Fires:

<protected> onVisible()

Called automatically by the Visibility Handler.
This will resume the main loop and then emit a resume event.

Since: 3.0.0
Source: src/boot/Game.js (Line 642)
Fires:

resize(width, height)

Updates the Game Config with the new width and height values given.
Then resizes the Renderer and Input Manager scale.

Parameters:
Name Type Description
width number

The new width of the game.

height number

The new height of the game.

Since: 3.2.0
Source: src/boot/Game.js (Line 698)
Fires:

<protected> start()

Called automatically by Game.boot once all of the global systems have finished setting themselves up.
By this point the Game is now ready to start the main loop running.
It will also enable the Visibility Handler.

Since: 3.0.0
Source: src/boot/Game.js (Line 401)

step(time, delta)

The main Game Step. Called automatically by the Time Step, once per browser frame (typically as a result of
Request Animation Frame, or Set Timeout on very old browsers.)

The step will update the global managers first, then proceed to update each Scene in turn, via the Scene Manager.

It will then render each Scene in turn, via the Renderer. This process emits prerender and postrender events.

Parameters:
Name Type Description
time number

The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.

delta number

The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.

Since: 3.0.0
Source: src/boot/Game.js (Line 500)
Fires:

Events


boot

Game boot event.

This is an internal event dispatched when the game has finished booting, but before it is ready to start running.
The global systems use this event to know when to set themselves up, dispatching their own ready events as required.

Source: src/boot/Game.js (Line 335)

destroyEvent

Game Destroy event.

Listen for it using the event type destroy.

Source: src/boot/Game.js (Line 732)

pauseEvent

Game Pause event.

Listen for it using the event type pause.

This event is dispatched when the game loop enters a paused state, usually as a result of the Visibility Handler.

Source: src/boot/Game.js (Line 606)

postrenderEvent

Game Post-Render event.

Listen for it using the event type postrender.

This event is dispatched right at the end of the render process.
Every Scene will have rendered and drawn to the canvas.

Parameters:
Name Type Description
renderer Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer

A reference to the current renderer.

Source: src/boot/Game.js (Line 488)

poststepEvent

Game Post-Step event.

Listen for it using the event type poststep.

This event is dispatched after the Scene Manager has updated.
Hook into it from plugins or systems that need to do things before the render starts.

Parameters:
Name Type Description
time number

The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.

delta number

The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.

Source: src/boot/Game.js (Line 462)

prerenderEvent

Game Pre-Render event.

Listen for it using the event type prerender.

This event is dispatched immediately before any of the Scenes have started to render.
The renderer will already have been initialized this frame, clearing itself and preparing to receive
the Scenes for rendering, but it won't have actually drawn anything yet.

Parameters:
Name Type Description
renderer Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer

A reference to the current renderer.

Source: src/boot/Game.js (Line 475)

prestepEvent

Game Pre-Step event.

Listen for it using the event type prestep.

This event is dispatched before the main Step starts.
By this point none of the Scene updates have happened.
Hook into it from plugins or systems that need to update before the Scene Manager does.

Parameters:
Name Type Description
time number

The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.

delta number

The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.

Source: src/boot/Game.js (Line 435)

resizeEvent

Game Resize event.

Listen for it using the event type resize.

Parameters:
Name Type Description
width number

The new width of the Game.

height number

The new height of the Game.

Source: src/boot/Game.js (Line 688)

resumeEvent

Game Resume event.

Listen for it using the event type resume.

This event is dispatched when the game loop leaves a paused state and resumes running.

Source: src/boot/Game.js (Line 632)

stepEvent

Game Step event.

Listen for it using the event type step.

This event is dispatched after Pre-Step and before the Scene Manager steps.
Hook into it from plugins or systems that need to update before the Scene Manager does, but after core Systems.

Parameters:
Name Type Description
time number

The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.

delta number

The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.

Source: src/boot/Game.js (Line 449)