Class: Game

The Phaser.Game object 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 Phaser systems, such as physics, sound and input.
Once that is complete it will start the default State, and then begin the main game loop.

You can access lots of the Phaser systems via the properties on the game object. For
example game.renderer is the Renderer, game.sound is the Sound Manager, and so on.

Anywhere you can access the game property, you can access all of these core systems.
For example a Sprite has a game property, allowing you to talk to the various parts
of Phaser directly, without having to look after your own references.

In its most simplest form, a Phaser game can be created by providing the arguments
to the constructor:

In the example above, 4 States are added to the State Manager, and Phaser is told to
start running the Boot state when it has finished initializing. There are example
project templates you can use in the Phaser GitHub repo, inside the resources folder.

Parameters:

The width of your game in game pixels. If given as a string the value must be between 0 and 100 and will be used as the percentage width of the parent container, or the browser window if no parent is given.

height

number
|
string

<optional>

600

The height of your game in game pixels. If given as a string the value must be between 0 and 100 and will be used as the percentage height of the parent container, or the browser window if no parent is given.

renderer

number

<optional>

Phaser.AUTO

Which renderer to use: Phaser.AUTO will auto-detect, Phaser.WEBGL, Phaser.WEBGL_MULTI, Phaser.CANVAS or Phaser.HEADLESS (no rendering at all).

parent

string
|
HTMLElement

<optional>

''

The DOM element into which this game canvas will be injected. Either a DOM id (string) or the element itself. If omitted (or no such element exists), the game canvas is appended to the document body.

state

object

<optional>

null

The default state object. A object consisting of Phaser.State functions (preload, create, update, render) or null.

transparent

boolean

<optional>

false

Use a transparent canvas background or not.

antialias

boolean

<optional>

true

Draw all image textures anti-aliased or not. The default is for smooth textures, but disable if your game features pixel art.

physicsConfig

object

<optional>

null

A physics configuration object to pass to the Physics world on creation.

Members

Type:

<readonly> antialias : boolean

Anti-alias graphics (as set when the Game is created). By default scaled and rotated images are smoothed in Canvas and WebGL; set antialias to false to disable this globally. After the game boots, use game.stage.smoothed instead.

canvas : HTMLCanvasElement

Type:

clearBeforeRender : boolean

Clear the Canvas each frame before rendering the display list.
You can set this to false to gain some performance if your game always contains a background that completely fills the display.
This must be true to show any Phaser.Stage#backgroundColor set on the Stage.
This is effectively read-only after the game has booted.
Use the GameConfig setting clearBeforeRender when creating the game, or set game.renderer.clearBeforeRender afterwards.

<readonly> isRunning : boolean

Type:

Type:

lockRender : boolean

If false Phaser will automatically render the display list every update. If true the render loop will be skipped.
You can toggle this value at run-time to gain exact control over when Phaser renders. This can be useful in certain types of game or application.
Please note that if you don't render the display list then none of the game object transforms will be updated, so use this value carefully.

Type:

Type:

<readonly> multiTexture : boolean

Has support for Multiple bound Textures in WebGL been enabled? This is a read-only property.
To set it you need to either specify Phaser.WEBGL_MULTI as the renderer type, or use the Game
Configuration object with the property multiTexture set to true. It has to be enabled before
Pixi boots, and cannot be changed after the game is running. Once enabled, take advantage of it
via the game.renderer.setTexturePriority method.

Type:

Type:

<readonly> parent : string | HTMLElement

The Game's DOM parent (or name thereof), if any, as set when the game was created. The actual parent can be found in game.canvas.parentNode. Setting this has no effect after Phaser.ScaleManager is booted.

Type:

Type:

paused : boolean

The paused state of the Game. A paused game doesn't update any of its subsystems.
When a game is paused the onPause event is dispatched. When it is resumed the onResume event is dispatched. Gets and sets the paused state of the Game.

Properties:

<readonly> renderType : number

The Renderer this game will use. Either Phaser.AUTO, Phaser.CANVAS, Phaser.WEBGL, Phaser.WEBGL_MULTI or Phaser.HEADLESS. After the game boots, renderType reflects the renderer in use: AUTO changes to CANVAS or WEBGL and WEBGL_MULTI changes to WEBGL. HEADLESS skips preRender, render, andpostRender` hooks, just like lockRender.

disableStep()

enableStep()

Enable core game loop stepping. When enabled you must call game.step() directly (perhaps via a DOM button?)
Calling step will advance the game loop by one frame. This is extremely useful for hard to track down errors!

<protected> showDebugHeader()

step()

When stepping is enabled you must call this function directly (perhaps via a DOM button?) to advance the game loop by one frame.
This is extremely useful to hard to track down errors! Use the internal stepCount property to monitor progress.

Parameters:

<protected> updateRender(elapsedTime)

Runs the Render cycle.
It starts by calling State.preRender. In here you can do any last minute adjustments of display objects as required.
It then calls the renderer, which renders the entire display list, starting from the Stage object and working down.
It then calls plugin.render on any loaded plugins, in the order in which they were enabled.
After this State.render is called. Any rendering that happens here will take place on-top of the display list.
Finally plugin.postRender is called on any loaded plugins, in the order in which they were enabled.
This method is called automatically by Game.update, you don't need to call it directly.
Should you wish to have fine-grained control over when Phaser renders then use the Game.lockRender boolean.
Phaser will only render when this boolean is false.