On this page
Class: Phaser.Game
Constructor
new Game(width, height, renderer, parent, state, transparent, antialias, physicsConfig)
This is where the magic happens. The Game object is the heart of your game,
providing quick access to common functions and handling the boot process.
"Hell, there are no rules here - we're trying to accomplish something."
Thomas A. Edison
Parameters
Name | Type | Argument | Default | Description |
---|---|---|---|---|
width |
number | string | <optional> |
800 | 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.CANVAS or Phaser.HEADLESS (no rendering at all). |
parent |
string | HTMLElement | <optional> |
'' | The DOM element into which this games canvas will be injected. Either a DOM ID (string) or the element itself. |
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. |
- Source code: core/Game.js (Line 25)
Public Properties
- Source code: core/Game.js (Line 156)
- Default Value
-
- true
- Source code: core/Game.js (Line 102)
- Source code: core/Game.js (Line 166)
- Source code: core/Game.js (Line 241)
- Source code: core/Game.js (Line 246)
- Default Value
-
- true
- Source code: core/Game.js (Line 116)
- Source code: core/Game.js (Line 36)
- Source code: core/Game.js (Line 251)
- Source code: core/Game.js (Line 266)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 336)
- Source code: core/Game.js (Line 256)
- Source code: core/Game.js (Line 236)
- Source code: core/Game.js (Line 380)
- Source code: core/Game.js (Line 375)
- Default Value
-
- 600
- Source code: core/Game.js (Line 69)
- Source code: core/Game.js (Line 31)
- Source code: core/Game.js (Line 171)
- Source code: core/Game.js (Line 139)
- Source code: core/Game.js (Line 145)
- Source code: core/Game.js (Line 176)
- Source code: core/Game.js (Line 275)
- Source code: core/Game.js (Line 161)
- Source code: core/Game.js (Line 181)
- Source code: core/Game.js (Line 186)
- Source code: core/Game.js (Line 311)
- Source code: core/Game.js (Line 316)
- Source code: core/Game.js (Line 301)
- Source code: core/Game.js (Line 306)
- string | HTMLElement
- Source code: core/Game.js (Line 47)
- Source code: core/Game.js (Line 261)
- Source code: core/Game.js (Line 1154)
- Source code: core/Game.js (Line 289)
- Source code: core/Game.js (Line 221)
- Source code: core/Game.js (Line 41)
- Source code: core/Game.js (Line 226)
- Source code: core/Game.js (Line 108)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 151)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 122)
- Source code: core/Game.js (Line 128)
- Default Value
-
- 1
- Source code: core/Game.js (Line 78)
- Source code: core/Game.js (Line 231)
- Source code: core/Game.js (Line 191)
- Source code: core/Game.js (Line 196)
- Source code: core/Game.js (Line 201)
- Source code: core/Game.js (Line 133)
- Source code: core/Game.js (Line 296)
- Source code: core/Game.js (Line 282)
- Source code: core/Game.js (Line 206)
- Source code: core/Game.js (Line 96)
- Source code: core/Game.js (Line 211)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 343)
- Default Value
-
- 800
- Source code: core/Game.js (Line 58)
- Source code: core/Game.js (Line 216)
add : Phaser.GameObjectFactory
Reference to the Phaser.GameObjectFactory.
antialias : boolean
Anti-alias graphics. By default scaled images are smoothed in Canvas and WebGL, set anti-alias to false to disable this globally.
cache : Phaser.Cache
Reference to the assets cache.
camera : Phaser.Camera
A handy reference to world.camera.
canvas :HTMLCanvasElement
A handy reference to renderer.view, the canvas that the game is being rendered in to.
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.
config : Object
The Phaser.Game configuration object.
context :CanvasRenderingContext2D
A handy reference to renderer.context (only set for CANVAS games, not WebGL)
create : Phaser.Create
The Asset Generator.
<internal> currentUpdateID : integer
The ID of the current/last logic update applied this render frame, starting from 0.
The first update is currentUpdateID === 0
and the last update is currentUpdateID === updatesThisFrame.
debug : Phaser.Utils.Debug
A set of useful debug utilities.
device : Phaser.Device
Contains device information and capabilities.
forceSingleUpdate : boolean
Should the game loop force a logic update, regardless of the delta timer? Set to true if you know you need this. You can toggle it on the fly.
fpsProblemNotifier : Phaser.Signal
If the game is struggling to maintain the desired FPS, this signal will be dispatched.
The desired/chosen FPS should probably be closer to the Phaser.Time#suggestedFps value.
[readonly] height : integer
The current Game Height in pixels.
Do not modify this property directly: use Phaser.ScaleManager#setGameSize - eg. game.scale.setGameSize(width, height)
- instead.
[readonly] id : number
Phaser Game ID (for when Pixi supports multiple instances).
input : Phaser.Input
Reference to the input manager
[readonly] isBooted : boolean
Whether the game engine is booted, aka available.
[readonly] isRunning : boolean
Is game running or paused?
load : Phaser.Loader
Reference to the assets loader.
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.
make : Phaser.GameObjectCreator
Reference to the GameObject Creator.
math : Phaser.Math
Reference to the math helper.
net : Phaser.Net
Reference to the network class.
onBlur : Phaser.Signal
This event is fired when the game no longer has focus (typically on page hide).
onFocus : Phaser.Signal
This event is fired when the game has focus (typically on page show).
onPause : Phaser.Signal
This event is fired when the game pauses.
onResume : Phaser.Signal
This event is fired when the game resumes from a paused state.
parent : string | HTMLElement
The Games DOM parent.
Type
particles : Phaser.Particles
The Particle Manager.
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.
[readonly] pendingStep : boolean
An internal property used by enableStep, but also useful to query from your own game objects.
physics : Phaser.Physics
Reference to the physics manager.
physicsConfig : Object
The Phaser.Physics.World configuration object.
plugins : Phaser.PluginManager
Reference to the plugin manager.
preserveDrawingBuffer : boolean
The value of the preserveDrawingBuffer flag affects whether or not the contents of the stencil buffer is retained after rendering.
<internal> raf : Phaser.RequestAnimationFrame
Automatically handles the core game loop via requestAnimationFrame or setTimeout
<internal> renderer : PIXI.CanvasRenderer | PIXI.WebGLRenderer
The Pixi Renderer.
Type
[readonly] renderType : number
The Renderer this game will use. Either Phaser.AUTO, Phaser.CANVAS, Phaser.WEBGL, or Phaser.HEADLESS.
[readonly] resolution : integer
The resolution of your game. This value is read only, but can be changed at start time it via a game configuration object.
rnd : Phaser.RandomDataGenerator
Instance of repeatable random data generator helper.
scale : Phaser.ScaleManager
The game scale manager.
sound : Phaser.SoundManager
Reference to the sound manager.
stage : Phaser.Stage
Reference to the stage.
state : Phaser.StateManager
The StateManager.
[readonly] stepCount : number
When stepping is enabled this contains the current step cycle.
[readonly] stepping : boolean
Enable core loop stepping with Game.enableStep().
time : Phaser.Time
Reference to the core game clock.
transparent : boolean
Use a transparent canvas background or not.
tweens : Phaser.TweenManager
Reference to the tween manager.
<internal> updatesThisFrame : integer
Number of logic updates expected to occur this render frame; will be 1 unless there are catch-ups required (and allowed).
[readonly] width : integer
The current Game Width in pixels.
Do not modify this property directly: use Phaser.ScaleManager#setGameSize - eg. game.scale.setGameSize(width, height)
- instead.
world : Phaser.World
Reference to the world.
Public Methods
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 520)
- Source code: core/Game.js (Line 1001)
- Source code: core/Game.js (Line 976)
- Source code: core/Game.js (Line 962)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 1132)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 1114)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 1048)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 1080)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 440)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 676)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 609)
- Source code: core/Game.js (Line 988)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 777)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 877)
- Internal:
-
- This member is internal (protected) and may be modified or removed in the future.
- Source code: core/Game.js (Line 925)
<internal> boot()
Initialize engine sub modules and start the game.
destroy()
Nukes the entire game from orbit.
Calls destroy on Game.state, Game.sound, Game.scale, Game.stage, Game.input, Game.physics and Game.plugins.
Then sets all of those local handlers to null, destroys the renderer, removes the canvas from the DOM
and resets the PIXI default renderer.
disableStep()
Disables core game loop stepping.
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!
<internal> focusGain(event)
Called by the Stage visibility handler.
Parameters
Name | Type | Description |
---|---|---|
event |
object | The DOM event that caused the game to pause, if any. |
<internal> focusLoss(event)
Called by the Stage visibility handler.
Parameters
Name | Type | Description |
---|---|---|
event |
object | The DOM event that caused the game to pause, if any. |
<internal> gamePaused(event)
Called by the Stage visibility handler.
Parameters
Name | Type | Description |
---|---|---|
event |
object | The DOM event that caused the game to pause, if any. |
<internal> gameResumed(event)
Called by the Stage visibility handler.
Parameters
Name | Type | Description |
---|---|---|
event |
object | The DOM event that caused the game to pause, if any. |
<internal> parseConfig()
Parses a Game configuration object.
<internal> setUpRenderer()
Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
<internal> showDebugHeader()
Displays a Phaser version debug header in the console.
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.
<internal> update(time)
The core game loop.
Parameters
Name | Type | Description |
---|---|---|
time |
number | The current time as provided by RequestAnimationFrame. |
<internal> updateLogic(timeStep)
Updates all logic subsystems in Phaser. Called automatically by Game.update.
Parameters
Name | Type | Description |
---|---|---|
timeStep |
number | The current timeStep value as determined by Game.update. |
<internal> 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
.
Parameters
Name | Type | Description |
---|---|---|
elapsedTime |
number | The time elapsed since the last update. |
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.Game.html