Options
All
  • Public
  • Public/Protected
  • All
Menu

Main Phaser game class

Hierarchy

  • Game
    • Game

Index

Constructors

constructor

  • Parameters

    Returns Game

Properties

add

add: GameObjectFactory

Reference to the Phaser.GameObjectFactory.

antialias

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: true

cache

cache: Cache

Reference to the assets cache.

camera

camera: Camera

A handy reference to world.camera.

canvas

canvas: HTMLCanvasElement

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

clearBeforeRender

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. Default: true

config

config: IGameConfig

The Phaser.Game configuration object.

context

context: CanvasRenderingContext2D

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

count

count: number

create

create: Create

The Asset Generator.

currentUpdateID

currentUpdateID: number

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

debug: Debug

A set of useful debug utilities.

device

device: Device

Contains device information and capabilities.

forceSingleUpdate

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

fpsProblemNotifier: 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 {@link Phaser.Time#suggestedFps} value.

height

height: number

The current Game Height in pixels.

Do not modify this property directly: use {@link Phaser.ScaleManager#setGameSize} - eg. game.scale.setGameSize(width, height) - instead. Default: 600

id

id: number

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

input

input: Input

Reference to the input manager

isBooted

isBooted: boolean

Whether the game engine is booted, aka available.

isRunning

isRunning: boolean

Is game running or paused?

load

load: Loader

Reference to the assets loader.

lockRender

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

make: GameObjectCreator

Reference to the GameObject Creator.

math

math: Math

Reference to the math helper.

net

net: Net

Reference to the network class.

onBlur

onBlur: Signal

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

Readonly onBootCompleted

onBootCompleted: Signal

Signal that fires when the boot phase/state has completed (and before the preloader starts)

onFocus

onFocus: Signal

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

Readonly onNewProgress

onNewProgress: Signal

Signal that fires when a new progress is deemed necessary (No progress yet exists, progress is complete, or is incompatable) Progress is deemed incompatable if: * Progress state 'major' is more than one version behind activity 'major' version -> create new progress

  • Progress state 'major' version is less than the activity 'major' version -> attempt to transform progress

Callback should initialize ProgressTracker and set progress.state as needed by the activity

onPause

onPause: Signal

This event is fired when the game pauses.

Readonly onPreloaderCompleted

onPreloaderCompleted: Signal

Signal that fires when the preload phase/state has completed (before the initial activity state/scene starts)

onResume

onResume: Signal

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

Readonly onTransformProgress

onTransformProgress: Signal

Signal that fires when the existing progress version is ONE 'major' version behind activity

Callback should:

  • transform existing progress state.
  • SZ.Game.transformSuccessful needs to be set depending on wether the transform was successful or not.

parent

parent: HTMLElement

The Games DOM parent.

particles

particles: Particles

The Particle Manager.

paused

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.

pendingStep

pendingStep: boolean

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

physics

physics: Physics

Reference to the physics manager.

physicsConfig

physicsConfig: any

The Phaser.Physics.World configuration object.

plugins

plugins: PluginManager

Reference to the plugin manager.

preserveDrawingBuffer

preserveDrawingBuffer: Boolean

The value of the preserveDrawingBuffer flag affects whether or not the contents of the stencil buffer is retained after rendering.

progressTransformSuccessful

progressTransformSuccessful: boolean

raf

raf: RequestAnimationFrame

Automatically handles the core game loop via requestAnimationFrame or setTimeout

renderType

renderType: number

The Renderer this game will use. Either Phaser.AUTO, Phaser.CANVAS, Phaser.WEBGL, or Phaser.HEADLESS.

renderer

renderer: CanvasRenderer | WebGLRenderer

The Pixi Renderer.

resolution

resolution: number

The resolution of your game. This value is read only, but can be changed at start time it via a game configuration object. Default: 1

rnd

rnd: RandomDataGenerator

Instance of repeatable random data generator helper.

scale

scale: ScaleManager

The game scale manager.

scratch

scratch: BitmapData

sound

sound: SoundManager

Reference to the sound manager.

stage

stage: Stage

Reference to the stage.

state

state: StateManager

The StateManager.

stepCount

stepCount: number

When stepping is enabled this contains the current step cycle.

stepping

stepping: boolean

Enable core loop stepping with Game.enableStep().

time

time: Time

Reference to the core game clock.

transparent

transparent: boolean

Use a transparent canvas background or not.

tweens

tweens: TweenManager

Reference to the tween manager.

updatesThisFrame

updatesThisFrame: number

Number of logic updates expected to occur this render frame; will be 1 unless there are catch-ups required (and allowed).

width

width: number

The current Game Width in pixels.

Do not modify this property directly: use {@link Phaser.ScaleManager#setGameSize} - eg. game.scale.setGameSize(width, height) - instead. Default: 800

world

world: World

Reference to the world.

Accessors

activityConfig

  • get activityConfig(): any
  • Returns object loaded from activity-config.json

    Returns any

assets

  • Return the collection of assets used for the activity. Items in this collection before startUp will be preloaded.

    Returns AssetCollection

overlayButtonPressedEvent

  • get overlayButtonPressedEvent(): Signal
  • Returns the signal used when an overlay button is pressed. These buttons are currently supported: ("backward"|"forward"|"home")

    Returns Signal

requestedOrientation

  • get requestedOrientation(): "landscape" | "portrait" | "any"
  • Returns the orientation the activity requested

    Returns "landscape" | "portrait" | "any"

Methods

boot

  • boot(): void
  • Initialize engine sub modules and start the game.

    Returns void

checkFrameworkUpdateTimer

  • checkFrameworkUpdateTimer(): void
  • Adds or removes this frameworks 'update' timer if needed. This timer is used for internal/framework updates and this function should only need to be called internally by the framework

    Returns void

checkProgress

  • checkProgress(): void
  • Called when the Preloader is completed (before activity's initial state/scene). This checks for existing progress and compares its version to the current activity's version, then dispatches onNewProgress or onTransformProgress Progress is deemed incompatable if:

    • Progress state 'major' is more than one version behind activity 'major' version -> create new progress
    • Progress state 'major' version is less than the activity 'major' version -> attempt to transform progress

    Returns void

destroy

  • destroy(): void
  • 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.

    Returns void

disableStep

  • disableStep(): void
  • Disables core game loop stepping.

    Returns void

enableStep

  • enableStep(): void
  • 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!

    Returns void

focusGain

  • focusGain(event: any): void
  • Called by the Stage visibility handler.

    Parameters

    • event: any

      The DOM event that caused the game to pause, if any.

    Returns void

focusLoss

  • focusLoss(event: any): void
  • Called by the Stage visibility handler.

    Parameters

    • event: any

      The DOM event that caused the game to pause, if any.

    Returns void

gamePaused

  • gamePaused(event: any): void
  • Called by the Stage visibility handler.

    Parameters

    • event: any

      The DOM event that caused the game to pause, if any.

    Returns void

gameResumed

  • gameResumed(event: any): void
  • Called by the Stage visibility handler.

    Parameters

    • event: any

      The DOM event that caused the game to pause, if any.

    Returns void

parseConfig

  • parseConfig(config: any): void
  • Parses a Game configuration object.

    Parameters

    • config: any

    Returns void

removeFromDOM

  • removeFromDOM(canvas: HTMLCanvasElement): void
  • Parameters

    • canvas: HTMLCanvasElement

    Returns void

resize

  • resize(minWidth: number, minHeight: number, fillScreen: boolean, orientation?: "landscape" | "portrait" | "any", ignorePixelDensity?: boolean): { height: number; width: number }
  • Resize the game to best match the requested params

    Parameters

    • minWidth: number

      Min width in pixels

    • minHeight: number

      Min height in pixels

    • fillScreen: boolean

      Attemps to fill screen (while maintaining aspect)

    • Default value orientation: "landscape" | "portrait" | "any" = "any"

      Required orientation. Defaults to "any"

    • Default value ignorePixelDensity: boolean = true

      Ignore pixel density when calculating size. Defaults to true.

    Returns { height: number; width: number }

    • height: number
    • width: number

setUpRenderer

  • setUpRenderer(): void
  • Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.

    Returns void

showDebugHeader

  • showDebugHeader(): void
  • Displays a Phaser version debug header in the console.

    Returns void

startUp

  • startUp(activityStartState: string): void
  • Start the boot and preload process. Once that is completed, start the activityStartState

    Parameters

    • activityStartState: string

    Returns void

step

  • step(): void
  • 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.

    Returns void

update

  • update(time: number): void
  • The core game loop.

    Parameters

    • time: number

      The current time as provided by RequestAnimationFrame.

    Returns void

updateLogic

  • updateLogic(timeStep: number): void
  • Updates all logic subsystems in Phaser. Called automatically by Game.update.

    Parameters

    • timeStep: number

      The current timeStep value as determined by Game.update.

    Returns void

updateRender

  • updateRender(timeStep: number): void
  • 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

    • timeStep: number

    Returns void