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 - core/Game.js, line 24
Members
-
add :Phaser.GameObjectFactory
-
Reference to the Phaser.GameObjectFactory.
- Source - core/Game.js, line 134
-
antialias :boolean
-
Anti-alias graphics. By default scaled images are smoothed in Canvas and WebGL, set anti-alias to false to disable this globally.
- Default Value:
- true
- Source - core/Game.js, line 91
-
cache :Phaser.Cache
-
Reference to the assets cache.
- Source - core/Game.js, line 144
-
camera :Phaser.Camera
-
A handy reference to world.camera.
- Source - core/Game.js, line 214
-
canvas :HTMLCanvasElement
-
A handy reference to renderer.view, the canvas that the game is being rendered in to.
- Source - core/Game.js, line 219
-
config :object
-
The Phaser.Game configuration object.
- Source - core/Game.js, line 34
-
context :CanvasRenderingContext2D
-
A handy reference to renderer.context (only set for CANVAS games, not WebGL)
- Source - core/Game.js, line 224
-
debug :Phaser.Utils.Debug
-
A set of useful debug utilitie.
- Source - core/Game.js, line 229
-
device :Phaser.Device
-
Contains device information and capabilities.
- Source - core/Game.js, line 209
-
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.
- Source - core/Game.js, line 317
-
fpsProblemNotifier :Phaser.Signal
-
if the game is struggling to maintain the desiredFps, this signal will be dispatched to suggest that the program adjust it's fps closer to the Time.suggestedFps value
- Source - core/Game.js, line 312
-
<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.- Default Value:
- 600
- Source - core/Game.js, line 67
-
id :number
-
Phaser Game ID (for when Pixi supports multiple instances).
- Source - core/Game.js, line 29
-
input :Phaser.Input
-
Reference to the input manager
- Source - core/Game.js, line 149
-
isBooted :boolean
-
Whether the game engine is booted, aka available.
- Default Value:
- false
- Source - core/Game.js, line 118
-
isRunning
-
- Default Value:
- false
- Source - core/Game.js, line 124
Properties:
Name Type Description id
boolean Is game running or paused?
-
load :Phaser.Loader
-
Reference to the assets loader.
- Source - core/Game.js, line 154
-
make :Phaser.GameObjectCreator
-
Reference to the GameObject Creator.
- Source - core/Game.js, line 139
-
math :Phaser.Math
-
Reference to the math helper.
- Source - core/Game.js, line 159
-
net :Phaser.Net
-
Reference to the network class.
- Source - core/Game.js, line 164
-
onBlur :Phaser.Signal
-
This event is fired when the game no longer has focus (typically on page hide).
- Source - core/Game.js, line 270
-
onFocus :Phaser.Signal
-
This event is fired when the game has focus (typically on page show).
- Source - core/Game.js, line 275
-
onPause :Phaser.Signal
-
This event is fired when the game pauses.
- Source - core/Game.js, line 260
-
onResume :Phaser.Signal
-
This event is fired when the game resumes from a paused state.
- Source - core/Game.js, line 265
-
parent :string|HTMLElement
-
The Games DOM parent.
Type:
- string | HTMLElement
- Source - core/Game.js, line 45
-
particles :Phaser.Particles
-
The Particle Manager.
- Source - core/Game.js, line 234
-
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.
- Source - core/Game.js, line 998
-
<readonly> pendingStep :boolean
-
An internal property used by enableStep, but also useful to query from your own game objects.
- Default Value:
- false
- Source - core/Game.js, line 248
-
physics :Phaser.Physics
-
Reference to the physics manager.
- Source - core/Game.js, line 199
-
physicsConfig :object
-
The Phaser.Physics.World configuration object.
- Source - core/Game.js, line 39
-
preserveDrawingBuffer :boolean
-
The value of the preserveDrawingBuffer flag affects whether or not the contents of the stencil buffer is retained after rendering.
- Default Value:
- false
- Source - core/Game.js, line 97
-
raf :Phaser.RequestAnimationFrame
-
Automatically handles the core game loop via requestAnimationFrame or setTimeout
- Source - core/Game.js, line 129
-
renderer :PIXI.CanvasRenderer|PIXI.WebGLRenderer
-
The Pixi Renderer.
Type:
- Source - core/Game.js, line 102
-
renderType :number
-
The Renderer this game will use. Either Phaser.AUTO, Phaser.CANVAS or Phaser.WEBGL.
- Source - core/Game.js, line 107
-
rnd :Phaser.RandomDataGenerator
-
Instance of repeatable random data generator helper.
- Source - core/Game.js, line 204
-
scale :Phaser.ScaleManager
-
The game scale manager.
- Source - core/Game.js, line 169
-
sound :Phaser.SoundManager
-
Reference to the sound manager.
- Source - core/Game.js, line 174
-
stage :Phaser.Stage
-
Reference to the stage.
- Source - core/Game.js, line 179
-
state :Phaser.StateManager
-
The StateManager.
- Source - core/Game.js, line 112
-
<readonly> stepCount :number
-
When stepping is enabled this contains the current step cycle.
- Default Value:
- 0
- Source - core/Game.js, line 255
-
<readonly> stepping :boolean
-
Enable core loop stepping with Game.enableStep().
- Default Value:
- false
- Source - core/Game.js, line 241
-
time :Phaser.Time
-
Reference to the core game clock.
- Source - core/Game.js, line 184
-
transparent :boolean
-
Use a transparent canvas background or not.
- Default Value:
- false
- Source - core/Game.js, line 85
-
tweens :Phaser.TweenManager
-
Reference to the tween manager.
- Source - core/Game.js, line 189
-
<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.- Default Value:
- 800
- Source - core/Game.js, line 56
-
world :Phaser.World
-
Reference to the world.
- Source - core/Game.js, line 194
Methods
-
<internal> boot()
-
Initialize engine sub modules and start the game.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - core/Game.js, line 452
-
destroy()
-
Nukes the entire game from orbit.
- Source - core/Game.js, line 860
-
disableStep()
-
Disables core game loop stepping.
- Source - core/Game.js, line 835
-
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!
- Source - core/Game.js, line 821
-
<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:
- This member is internal (protected) and may be modified or removed in the future.
- Source - core/Game.js, line 976
-
<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:
- This member is internal (protected) and may be modified or removed in the future.
- Source - core/Game.js, line 958
-
<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:
- This member is internal (protected) and may be modified or removed in the future.
- Source - core/Game.js, line 917
-
<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:
- This member is internal (protected) and may be modified or removed in the future.
- Source - core/Game.js, line 937
-
<internal> parseConfig()
-
Parses a Game configuration object.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - core/Game.js, line 377
-
<internal> setUpRenderer()
-
Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - core/Game.js, line 586
-
<internal> showDebugHeader()
-
Displays a Phaser version debug header in the console.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - core/Game.js, line 524
-
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.
- Source - core/Game.js, line 847
-
<internal> update(time)
-
The core game loop.
Parameters:
Name Type Description time
number The current time as provided by RequestAnimationFrame.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - core/Game.js, line 661
-
<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:
- This member is internal (protected) and may be modified or removed in the future.
- Source - core/Game.js, line 735
-
<internal> updateRender(elapsedTime)
-
Renders the display list. Called automatically by Game.update.
Parameters:
Name Type Description elapsedTime
number The time elapsed since the last update.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - core/Game.js, line 788