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:
Members
-
add
-
- Source:
Properties:
Name Type Description addPhaser.GameObjectFactory Reference to the Phaser.GameObjectFactory.
-
antialias
-
- Default Value:
- true
- Source:
Properties:
Name Type Description antialiasboolean Anti-alias graphics. By default scaled images are smoothed in Canvas and WebGL, set anti-alias to false to disable this globally.
-
cache
-
- Source:
Properties:
Name Type Description cachePhaser.Cache Reference to the assets cache.
-
camera
-
- Source:
Properties:
Name Type Description cameraPhaser.Camera A handy reference to world.camera.
-
canvas
-
- Source:
Properties:
Name Type Description canvasHTMLCanvasElement A handy reference to renderer.view, the canvas that the game is being rendered in to.
-
config
-
- Source:
Properties:
Name Type Description configobject The Phaser.Game configuration object.
-
context
-
- Source:
Properties:
Name Type Description contextCanvasRenderingContext2D A handy reference to renderer.context (only set for CANVAS games, not WebGL)
-
debug
-
- Source:
Properties:
Name Type Description debugPhaser.Utils.Debug A set of useful debug utilitie.
-
device
-
- Source:
Properties:
Name Type Description devicePhaser.Device Contains device information and capabilities.
-
height
-
- Default Value:
- 600
- Source:
Properties:
Name Type Description heightnumber The calculated game height in pixels.
-
id
-
- Source:
Properties:
Name Type Description idnumber Phaser Game ID (for when Pixi supports multiple instances).
-
input
-
- Source:
Properties:
Name Type Description inputPhaser.Input Reference to the input manager
-
isBooted
-
- Default Value:
- false
- Source:
Properties:
Name Type Description isBootedboolean Whether the game engine is booted, aka available.
-
isRunning
-
- Default Value:
- false
- Source:
Properties:
Name Type Description idboolean Is game running or paused?
-
load
-
- Source:
Properties:
Name Type Description loadPhaser.Loader Reference to the assets loader.
-
make
-
- Source:
Properties:
Name Type Description makePhaser.GameObjectCreator Reference to the GameObject Creator.
-
math
-
- Source:
Properties:
Name Type Description mathPhaser.Math Reference to the math helper.
-
net
-
- Source:
Properties:
Name Type Description netPhaser.Net Reference to the network class.
-
onBlur
-
- Source:
Properties:
Name Type Description onBlurPhaser.Signal This event is fired when the game no longer has focus (typically on page hide).
-
onFocus
-
- Source:
Properties:
Name Type Description onFocusPhaser.Signal This event is fired when the game has focus (typically on page show).
-
onPause
-
- Source:
Properties:
Name Type Description onPausePhaser.Signal This event is fired when the game pauses.
-
onResume
-
- Source:
Properties:
Name Type Description onResumePhaser.Signal This event is fired when the game resumes from a paused state.
-
parent
-
- Source:
Properties:
Name Type Description parentstring | HTMLElement The Games DOM parent.
-
particles
-
- Source:
Properties:
Name Type Description particlesPhaser.Particles The Particle Manager.
-
paused
-
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.
- Source:
Properties:
Name Type Description pausedboolean Gets and sets the paused state of the Game.
-
<readonly> pendingStep
-
- Default Value:
- false
- Source:
Properties:
Name Type Description pendingStepboolean An internal property used by enableStep, but also useful to query from your own game objects.
-
physics
-
- Source:
Properties:
Name Type Description physicsPhaser.Physics Reference to the physics manager.
-
physicsConfig
-
- Source:
Properties:
Name Type Description physicsConfigobject The Phaser.Physics.World configuration object.
-
preserveDrawingBuffer
-
- Default Value:
- false
- Source:
Properties:
Name Type Description preserveDrawingBufferboolean The value of the preserveDrawingBuffer flag affects whether or not the contents of the stencil buffer is retained after rendering.
-
raf
-
- Source:
Properties:
Name Type Description rafPhaser.RequestAnimationFrame Automatically handles the core game loop via requestAnimationFrame or setTimeout
-
renderer
-
- Source:
Properties:
Name Type Description rendererPIXI.CanvasRenderer | PIXI.WebGLRenderer The Pixi Renderer.
-
renderType
-
- Source:
Properties:
Name Type Description renderTypenumber The Renderer this game will use. Either Phaser.AUTO, Phaser.CANVAS or Phaser.WEBGL.
-
rnd
-
- Source:
Properties:
Name Type Description rndPhaser.RandomDataGenerator Instance of repeatable random data generator helper.
-
scale
-
- Source:
Properties:
Name Type Description scalePhaser.ScaleManager The game scale manager.
-
sound
-
- Source:
Properties:
Name Type Description soundPhaser.SoundManager Reference to the sound manager.
-
stage
-
- Source:
Properties:
Name Type Description stagePhaser.Stage Reference to the stage.
-
state
-
- Source:
Properties:
Name Type Description statePhaser.StateManager The StateManager.
-
<readonly> stepCount
-
- Default Value:
- 0
- Source:
Properties:
Name Type Description stepCountnumber When stepping is enabled this contains the current step cycle.
-
<readonly> stepping
-
- Default Value:
- false
- Source:
Properties:
Name Type Description steppingboolean Enable core loop stepping with Game.enableStep().
-
time
-
- Source:
Properties:
Name Type Description timePhaser.Time Reference to the core game clock.
-
transparent
-
- Default Value:
- false
- Source:
Properties:
Name Type Description transparentboolean Use a transparent canvas background or not.
-
tweens
-
- Source:
Properties:
Name Type Description tweensPhaser.TweenManager Reference to the tween manager.
-
width
-
- Default Value:
- 800
- Source:
Properties:
Name Type Description widthnumber The calculated game width in pixels.
-
world
-
- Source:
Properties:
Name Type Description worldPhaser.World Reference to the world.
Methods
-
<protected> boot()
-
Initialize engine sub modules and start the game.
- Source:
-
destroy()
-
Nukes the entire game from orbit.
- Source:
-
disableStep()
-
Disables core game loop stepping.
- Source:
-
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:
-
<protected> focusGain(event)
-
Called by the Stage visibility handler.
Parameters:
Name Type Description eventobject The DOM event that caused the game to pause, if any.
- Source:
-
<protected> focusLoss(event)
-
Called by the Stage visibility handler.
Parameters:
Name Type Description eventobject The DOM event that caused the game to pause, if any.
- Source:
-
<protected> gamePaused(event)
-
Called by the Stage visibility handler.
Parameters:
Name Type Description eventobject The DOM event that caused the game to pause, if any.
- Source:
-
<protected> gameResumed(event)
-
Called by the Stage visibility handler.
Parameters:
Name Type Description eventobject The DOM event that caused the game to pause, if any.
- Source:
-
<protected> parseConfig()
-
Parses a Game configuration object.
- Source:
-
<protected> setUpRenderer()
-
Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
- Source:
-
<protected> showDebugHeader()
-
Displays a Phaser version debug header in the console.
- Source:
-
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:
-
<protected> update(time)
-
The core game loop.
Parameters:
Name Type Description timenumber The current time as provided by RequestAnimationFrame.
- Source: