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.
Callbacks
start | preload | loaded | paused | stop |
---|---|---|---|---|
init | ||||
preload | create | paused | ||
loadUpdate* | update* | pauseUpdate* | ||
postUpdate* | ||||
preRender* | ||||
loadRender* | render* | render* | ||
resumed | ||||
shutdown |
Update and render calls (*) are repeated.
If your State has a constructor, it will be invoked exactly once, during Phaser.StateManager#add.
- Source:
- src/core/State.js line 31
Members
-
add : Phaser.GameObjectFactory
-
A reference to the GameObjectFactory which can be used to add new objects to the World.
Type:
- Source:
- src/core/State.js line 46
-
cache : Phaser.Cache
-
A reference to the game cache which contains any loaded or generated assets, such as images, sound and more.
Type:
- Source:
- src/core/State.js line 61
-
camera : Phaser.Camera
-
A handy reference to World.camera.
Type:
- Source:
- src/core/State.js line 56
-
game : Phaser.Game
-
This is a reference to the currently running Game.
Type:
- Source:
- src/core/State.js line 36
-
input : Phaser.Input
-
A reference to the Input Manager.
Type:
- Source:
- src/core/State.js line 66
-
key : string
-
The string based identifier given to the State when added into the State Manager.
Type:
- string
- Source:
- src/core/State.js line 41
-
load : Phaser.Loader
-
A reference to the Loader, which you mostly use in the preload method of your state to load external assets.
Type:
- Source:
- src/core/State.js line 71
-
make : Phaser.GameObjectCreator
-
A reference to the GameObjectCreator which can be used to make new objects.
Type:
- Source:
- src/core/State.js line 51
-
math : Phaser.Math
-
A reference to Math class with lots of helpful functions.
Type:
- Source:
- src/core/State.js line 76
-
particles : Phaser.Particles
-
The Particle Manager. It is called during the core gameloop and updates any Particle Emitters it has created.
Type:
- Source:
- src/core/State.js line 116
-
physics : Phaser.Physics
-
A reference to the physics manager which looks after the different physics systems available within Phaser.
Type:
- Source:
- src/core/State.js line 121
-
rnd : Phaser.RandomDataGenerator
-
A reference to the seeded and repeatable random data generator.
Type:
- Source:
- src/core/State.js line 126
-
scale : Phaser.ScaleManager
-
A reference to the Scale Manager which controls the way the game scales on different displays.
Type:
- Source:
- src/core/State.js line 86
-
sound : Phaser.SoundManager
-
A reference to the Sound Manager which can create, play and stop sounds, as well as adjust global volume.
Type:
- Source:
- src/core/State.js line 81
-
stage : Phaser.Stage
-
A reference to the Stage.
Type:
- Source:
- src/core/State.js line 91
-
state : Phaser.StateManager
-
A reference to the State Manager, which controls state changes.
Type:
- Source:
- src/core/State.js line 96
-
time : Phaser.Time
-
A reference to the game clock and timed events system.
Type:
- Source:
- src/core/State.js line 101
-
tweens : Phaser.TweenManager
-
A reference to the tween manager.
Type:
- Source:
- src/core/State.js line 106
-
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.
Type:
- Source:
- src/core/State.js line 111
Methods
-
create(game)
-
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.
Parameters:
Name Type Description game
Phaser.Game - Source:
- src/core/State.js line 176
-
init(args)
-
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.
Parameters:
Name Type Argument Description args
any <repeatable>
Any extra arguments passed to Phaser.StateManager#start or Phaser.StateManager#restart.
- Source:
- src/core/State.js line 131
-
loadRender(game)
-
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.
Parameters:
Name Type Description game
Phaser.Game - Source:
- src/core/State.js line 165
-
loadUpdate(game)
-
loadUpdate is called during the Loader process. This only happens if you've set one or more assets to load in the preload method.
Parameters:
Name Type Description game
Phaser.Game - Source:
- src/core/State.js line 155
-
paused(game)
-
This method will be called if the core game loop is paused.
Parameters:
Name Type Description game
Phaser.Game - Source:
- src/core/State.js line 245
-
pauseUpdate(game)
-
pauseUpdate is called while the game is paused instead of preUpdate, update and postUpdate.
Parameters:
Name Type Description game
Phaser.Game - Source:
- src/core/State.js line 265
-
postUpdate(game)
-
The postUpdate method is left empty for your own use. It is called during the core game loop AFTER the Stage has had its postUpdate method called (including updateTransform). It is called BEFORE Plugins have had their postUpdate methods called. You don't need to call updateTransform yourself here unless Plugins need it.
Parameters:
Name Type Description game
Phaser.Game - Source:
- src/core/State.js line 199
-
preload(game)
-
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.
Parameters:
Name Type Description game
Phaser.Game - Source:
- src/core/State.js line 143
-
preRender(game)
-
The preRender method is called after all Game Objects have been updated, but before any rendering takes place.
Parameters:
Name Type Description game
Phaser.Game - Source:
- src/core/State.js line 212
-
render(game)
-
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.
Parameters:
Name Type Description game
Phaser.Game - Source:
- src/core/State.js line 222
-
resize(width, height)
-
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.
Parameters:
Name Type Description width
number height
number - Source:
- src/core/State.js line 234
-
resumed(game)
-
This method will be called when the core game loop resumes from a paused state.
Parameters:
Name Type Description game
Phaser.Game - Source:
- src/core/State.js line 255
-
shutdown(game)
-
This method will be called when the State is shutdown (i.e. you switch to another state from this one).
Parameters:
Name Type Description game
Phaser.Game - Source:
- src/core/State.js line 275
-
update(game)
-
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.
Parameters:
Name Type Description game
Phaser.Game - Source:
- src/core/State.js line 187