API Docs for: v0.1.0
Show:

Game Class

Extends Object
Defined in: src\game\Game.js:16

Main game object, controls the entire instance of the game

Constructor

Game

(
  • container
  • settings
)

Defined in src\game\Game.js:16

Parameters:

  • container DOMElement | String

    The container for the new canvas we will create for the game, or the ID of one

  • settings Object

    All the settings for the game instance

    • width Number

      The width of the viewport

    • height Number

      The height of the viewport

    • [renderer=RENDERER.AUTO] String optional

      The renderer to use either RENDERER.AUTO, RENDERER.CANVAS, or RENDERER.WEBGL

    • [transparent=false] Boolean optional

      Should the render element have a transparent background

    • [background='#FFF'] Number optional

      The background color of the stage

    • [antialias=true] Boolean optional

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

    • [canvas] DOMElement optional

      The canvas to render into, if not specified one is created

Methods

_createRenderer

() PIXI.WebGLRenderer | PIXI.CanvasRenderer private

Creates the underlying renderer based on browser support. It will also set's game.renderMethod for a user to be able to check.

Returns:

PIXI.WebGLRenderer | PIXI.CanvasRenderer:

The renderer to use

_tick

() private

The looping render tick.

emit

(
  • type
  • data
)
Mixed chainable

Emits an event which will run all registered listeners for the event type

Parameters:

  • type String

    The event name to emit

  • data Mixed

    Any data you want passed along with the event

Returns:

Mixed:

Returns itself.

off

(
  • type
  • listener
)
Mixed chainable

Removes a listener function for an event type

Parameters:

  • type String

    The event name to emit

  • listener Function

    The function to remove

Returns:

Mixed:

Returns itself.

on

(
  • type
  • listener
)
Mixed chainable

Registers a listener function to be run on an event occurance

Parameters:

  • type String

    The event name to listen for

  • listener Function

    The function to execute when the event happens

Returns:

Mixed:

Returns itself.

once

(
  • type
  • listener
)
Mixed chainable

Registers a one-time callback for an event

Parameters:

  • type String

    The event name to listen for

  • listener Function

    the callback to call when the event occurs

Returns:

Mixed:

Returns itself.

render

() Game chainable

Begins the render loop.

Returns:

Game:

Returns itself.

requestFullscreen

() Game chainable

Requests that the browser go into fullscreen mode.

Returns:

Game:

Returns itself.

resize

(
  • width
  • height
)
Game chainable

Allows you to resize the game area.

Parameters:

  • width Number

    Width to resize to

  • height Number

    Height to resize to

Returns:

Game:

Returns itself.

Properties

antialias

Boolean

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

Default: true

audio

AudioManager

The audio manager for this game instance, used to play and control all the audio in a game.

background

Boolean

Defined in src\game\Game.js:94

The background of the stage

Default: false

cache

Cache

Cache instance for storing/retrieving assets

camera

Camera

Alias for the active State's camera object. Instead of using game.state.active.camera, you can use game.camera

canvas

HTMLCanvasElement

The canvas to render into

clock

Clock

Clock instance for internal timing

container

DOMELement

Defined in src\game\Game.js:46

The domElement that we are putting our rendering canvas into (the container)

height

Number

Defined in src\game\Game.js:67

The height of the render viewport

Default: 600

input

InputManager

The input instance for this game

loader

Loader

The loader for this game instance, used to preload assets into the cache

offset

Vector

The offset for the viewport in the document

physics

Physics

Alias for the active State's physics object. Instead of using game.state.active.physics, you can use game.physics

renderer

PIXI.WebGLRenderer | PIXI.CanvasRenderer

Raw rendering engine, the underlying PIXI renderer that draws for us

renderMethod

String

Defined in src\game\Game.js:76

The method used to render values to the screen (either webgl, or canvas)

Default: RENDERER.AUTO

spritepool

SpritePool

The sprite pool to use to create registered entities

stage

PIXI.Stage

Raw PIXI.stage instance, the root of all things in the scene graph

state

StateManager

The state manager, to switch between game states

timings

Object

Holds timing data for the previous loop

transparent

Boolean

Defined in src\game\Game.js:85

Whether the canvas has a transparent background or not

Default: false

width

Number

Defined in src\game\Game.js:58

The width of the render viewport

Default: 800

world

World

Alias for the active State's world object. Instead of using game.state.active.world, you can use game.world

Events

tick

Fired each frame after everything has updated, but just before rendering

Event Payload:

  • dt Number

    The number of seconds passed since the last tick call (delta time)