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

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

Properties:
Name Type Description
add Phaser.GameObjectFactory

Reference to the Phaser.GameObjectFactory.

Source:

antialias

Properties:
Name Type Description
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:

cache

Properties:
Name Type Description
cache Phaser.Cache

Reference to the assets cache.

Source:

camera

Properties:
Name Type Description
camera Phaser.Camera

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 CanvasRenderingContext2D

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

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.

Source:

make

Properties:
Name Type Description
make Phaser.GameObjectCreator

Reference to the GameObject Creator.

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:

onBlur

Properties:
Name Type Description
onBlur Phaser.Signal

This event is fired when the game no longer has focus (typically on page hide).

Source:

onFocus

Properties:
Name Type Description
onFocus Phaser.Signal

This event is fired when the game has focus (typically on page show).

Source:

onPause

Properties:
Name Type Description
onPause Phaser.Signal

This event is fired when the game pauses.

Source:

onResume

Properties:
Name Type Description
onResume Phaser.Signal

This event is fired when the game resumes from a paused state.

Source:

parent

Properties:
Name Type Description
parent string | 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
pendingStep 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

Reference to the physics manager.

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 PIXI.CanvasRenderer | PIXI.WebGLRenderer

The Pixi Renderer.

Source:

renderType

Properties:
Name Type Description
renderType number

The Renderer this game will use. Either Phaser.AUTO, Phaser.CANVAS or Phaser.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.ScaleManager

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 Phaser.StateManager

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.Time

Reference to the core 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 for hard to track down errors!

Source:

<protected> 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.

Source:

<protected> 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.

Source:

<protected> 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.

Source:

<protected> 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.

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 when in a paused state.

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 Tue May 20 2014 10:05:56 GMT+0100 (BST) using the DocStrap template.