Class: Game

Phaser. Game

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

new Game(width, height, renderer, parent, state, transparent, antialias, physicsConfig)

Game constructor

Instantiate a new <code>Phaser.Game</code> object.

Parameters:
Name Type Argument Default Description
width number <optional>
800

The width of your game in game pixels.

height number <optional>
600

The height of your game in game pixels.

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

Anti-alias graphics.

physicsConfig object <optional>
null

A physics configuration object to pass to the Physics world on creation.

Source:

Members

add

Properties:
Name Type Description
add Phaser.GameObjectFactory

Reference to the GameObject Factory.

Source:

antialias

Properties:
Name Type Description
antialias boolean

Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality).

Default Value:
  • true
Source:

cache

Properties:
Name Type Description
cache Phaser.Cache

Reference to the assets cache.

Default Value:
  • null
Source:

camera

Properties:
Name Type Description
camera Phaser.Physics.PhysicsManager

A handy reference to world.camera.

Source:

canvas

Properties:
Name Type Description
canvas HTMLCanvasElement

A handy reference to renderer.view, the canvas that the game is being rendered in to.

Source:

config

Properties:
Name Type Description
config object

The Phaser.Game configuration object.

Source:

context

Properties:
Name Type Description
context Context

A handy reference to renderer.context (only set for CANVAS games, not WebGL)

Source:

debug

Properties:
Name Type Description
debug Phaser.Utils.Debug

A set of useful debug utilitie.

Source:

device

Properties:
Name Type Description
device Phaser.Device

Contains device information and capabilities.

Source:

height

Properties:
Name Type Description
height number

The Game height (in pixels).

Default Value:
  • 600
Source:

id

Properties:
Name Type Description
id number

Phaser Game ID (for when Pixi supports multiple instances).

Source:

input

Properties:
Name Type Description
input Phaser.Input

Reference to the input manager

Default Value:
  • null
Source:

isBooted

Properties:
Name Type Description
isBooted boolean

Whether the game engine is booted, aka available.

Default Value:
  • false
Source:

isRunning

Properties:
Name Type Description
id boolean

Is game running or paused?

Default Value:
  • false
Source:

load

Properties:
Name Type Description
load Phaser.Loader

Reference to the assets loader.

Default Value:
  • null
Source:

math

Properties:
Name Type Description
math Phaser.Math

Reference to the math helper.

Source:

net

Properties:
Name Type Description
net Phaser.Net

Reference to the network class.

Source:

parent

Properties:
Name Type Description
parent HTMLElement

The Games DOM parent.

Source:

particles

Properties:
Name Type Description
particles Phaser.Particles

The Particle Manager.

Source:

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.

Properties:
Name Type Description
paused boolean

Gets and sets the paused state of the Game.

Source:

<readonly> pendingStep

Properties:
Name Type Description
stepping boolean

An internal property used by enableStep, but also useful to query from your own game objects.

Default Value:
  • false
Source:

physics

Properties:
Name Type Description
physics Phaser.Physics.World

Reference to the physics world.

Source:

physicsConfig

Properties:
Name Type Description
physicsConfig object

The Phaser.Physics.World configuration object.

Source:

raf

Properties:
Name Type Description
raf Phaser.RequestAnimationFrame

Automatically handles the core game loop via requestAnimationFrame or setTimeout

Source:

renderer

Properties:
Name Type Description
renderer number

The Pixi Renderer

Source:

renderType

Properties:
Name Type Description
renderType number

The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL.

Source:

rnd

Properties:
Name Type Description
rnd Phaser.RandomDataGenerator

Instance of repeatable random data generator helper.

Source:

scale

Properties:
Name Type Description
scale Phaser.StageScaleMode

The game scale manager.

Source:

sound

Properties:
Name Type Description
sound Phaser.SoundManager

Reference to the sound manager.

Source:

stage

Properties:
Name Type Description
stage Phaser.Stage

Reference to the stage.

Source:

state

Properties:
Name Type Description
state number

The StateManager.

Source:

<readonly> stepCount

Properties:
Name Type Description
stepCount number

When stepping is enabled this contains the current step cycle.

Default Value:
  • 0
Source:

<readonly> stepping

Properties:
Name Type Description
stepping boolean

Enable core loop stepping with Game.enableStep().

Default Value:
  • false
Source:

time

Properties:
Name Type Description
time Phaser.TimeManager

Reference to game clock.

Source:

transparent

Properties:
Name Type Description
transparent boolean

Use a transparent canvas background or not.

Default Value:
  • false
Source:

tweens

Properties:
Name Type Description
tweens Phaser.TweenManager

Reference to the tween manager.

Source:

width

Properties:
Name Type Description
width number

The Game width (in pixels).

Default Value:
  • 800
Source:

world

Properties:
Name Type Description
world Phaser.World

Reference to the world.

Source:

Methods

<protected> boot()

Initialize engine sub modules and start the game.

Source:

destroy()

Nuke 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 to hard to track down errors!

Source:

<protected> loadComplete()

Called when the load has finished, after preload was run.

Source:

<protected> parseConfig()

Parses a Game configuration object.

Source:

<protected> parseDimension()

Get dimension.

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
time number

The current time as provided by RequestAnimationFrame.

Source:
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Wed Feb 19 2014 05:26:25 GMT-0000 (GMT) using the DocStrap template.