These archived docs are for Phaser 2.6.2 Phaser 3 docs can be found on
Phaser CE docs can be found on the Phaser CE Documentation site.


Phaser. State

new State()

This is a base State class which can be extended if you are creating your own game.
It provides quick access to common functions such as the camera, cache, input, match, sound and more.

Source code: core/State.js (Line 14)

Public Properties

add : Phaser.GameObjectFactory

A reference to the GameObjectFactory which can be used to add new objects to the World.

Source code: core/State.js (Line 29)

cache : Phaser.Cache

A reference to the game cache which contains any loaded or generated assets, such as images, sound and more.

Source code: core/State.js (Line 44)

camera : Phaser.Camera

A handy reference to

Source code: core/State.js (Line 39)

game : Phaser.Game

This is a reference to the currently running Game.

Source code: core/State.js (Line 19)

input : Phaser.Input

A reference to the Input Manager.

Source code: core/State.js (Line 49)

key : string

The string based identifier given to the State when added into the State Manager.

Source code: core/State.js (Line 24)

load : Phaser.Loader

A reference to the Loader, which you mostly use in the preload method of your state to load external assets.

Source code: core/State.js (Line 54)

make : Phaser.GameObjectCreator

A reference to the GameObjectCreator which can be used to make new objects.

Source code: core/State.js (Line 34)

math : Phaser.Math

A reference to Math class with lots of helpful functions.

Source code: core/State.js (Line 59)

particles : Phaser.Particles

The Particle Manager. It is called during the core gameloop and updates any Particle Emitters it has created.

Source code: core/State.js (Line 99)

physics : Phaser.Physics

A reference to the physics manager which looks after the different physics systems available within Phaser.

Source code: core/State.js (Line 104)

rnd : Phaser.RandomDataGenerator

A reference to the seeded and repeatable random data generator.

Source code: core/State.js (Line 109)

scale : Phaser.ScaleManager

A reference to the Scale Manager which controls the way the game scales on different displays.

Source code: core/State.js (Line 69)

sound : Phaser.SoundManager

A reference to the Sound Manager which can create, play and stop sounds, as well as adjust global volume.

Source code: core/State.js (Line 64)

stage : Phaser.Stage

A reference to the Stage.

Source code: core/State.js (Line 74)


Name Type Description
stage Phaser.StateManager

A reference to the State Manager, which controls state changes.

Source code: core/State.js (Line 79)

time : Phaser.Time

A reference to the game clock and timed events system.

Source code: core/State.js (Line 84)

tweens : Phaser.TweenManager

A reference to the tween manager.

Source code: core/State.js (Line 89)

world : Phaser.World

A reference to the game world. All objects live in the Game World and its size is not bound by the display resolution.

Source code: core/State.js (Line 94)

Public Methods


create is called once preload has completed, this includes the loading of any assets from the Loader.
If you don't have a preload method then create is the first method called in your State.

Source code: core/State.js (Line 152)


init is the very first function called when your State starts up. It's called before preload, create or anything else.
If you need to route the game away to another State you could do so here, or if you need to prepare a set of variables
or objects before the preloading starts.

Source code: core/State.js (Line 115)


loadRender is called during the Loader process. This only happens if you've set one or more assets to load in the preload method.
The difference between loadRender and render is that any objects you render in this method you must be sure their assets exist.

Source code: core/State.js (Line 143)


loadUpdate is called during the Loader process. This only happens if you've set one or more assets to load in the preload method.

Source code: core/State.js (Line 135)


This method will be called if the core game loop is paused.

Source code: core/State.js (Line 197)


pauseUpdate is called while the game is paused instead of preUpdate, update and postUpdate.

Source code: core/State.js (Line 213)


preload is called first. Normally you'd use this to load your game assets (or those needed for the current State)
You shouldn't create any objects in this method that require assets that you're also loading in this method, as
they won't yet be available.

Source code: core/State.js (Line 125)


The preRender method is called after all Game Objects have been updated, but before any rendering takes place.

Source code: core/State.js (Line 171)


Nearly all display objects in Phaser render automatically, you don't need to tell them to render.
However the render method is called AFTER the game renderer and plugins have rendered, so you're able to do any
final post-processing style effects here. Note that this happens before plugins postRender takes place.

Source code: core/State.js (Line 179)


If your game is set to Scalemode RESIZE then each time the browser resizes it will call this function, passing in the new width and height.

Source code: core/State.js (Line 189)


This method will be called when the core game loop resumes from a paused state.

Source code: core/State.js (Line 205)


This method will be called when the State is shutdown (i.e. you switch to another state from this one).

Source code: core/State.js (Line 221)


The update method is left empty for your own use.
It is called during the core game loop AFTER debug, physics, plugins and the Stage have had their preUpdate methods called.
It is called BEFORE Stage, Tweens, Sounds, Input, Physics, Particles and Plugins have had their postUpdate methods called.

Source code: core/State.js (Line 161)