Game Class
Main game object, controls the entire instance of the game
Constructor
Game
-
container
-
settings
Parameters:
-
container
DOMElement | StringThe container for the new canvas we will create for the game, or the ID of one
-
settings
ObjectAll the settings for the game instance
-
width
NumberThe width of the viewport
-
height
NumberThe height of the viewport
-
[renderer=RENDERER.AUTO]
String optionalThe renderer to use either RENDERER.AUTO, RENDERER.CANVAS, or RENDERER.WEBGL
-
[transparent=false]
Boolean optionalShould the render element have a transparent background
-
[background='#FFF']
Number optionalThe background color of the stage
-
[antialias=true]
Boolean optionalAnti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality)
-
[canvas]
DOMElement optionalThe canvas to render into, if not specified one is created
-
Item Index
Methods
Properties
Events
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:
The renderer to use
_tick
()
private
The looping render tick.
emit
-
type
-
data
Emits an event which will run all registered listeners for the event type
Parameters:
-
type
StringThe event name to emit
-
data
MixedAny data you want passed along with the event
Returns:
Returns itself.
off
-
type
-
listener
Removes a listener function for an event type
Parameters:
-
type
StringThe event name to emit
-
listener
FunctionThe function to remove
Returns:
Returns itself.
on
-
type
-
listener
Registers a listener function to be run on an event occurance
Parameters:
-
type
StringThe event name to listen for
-
listener
FunctionThe function to execute when the event happens
Returns:
Returns itself.
once
-
type
-
listener
Registers a one-time callback for an event
Parameters:
-
type
StringThe event name to listen for
-
listener
Functionthe callback to call when the event occurs
Returns:
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
The background of the stage
Default: false
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
container
DOMELement
The domElement that we are putting our rendering canvas into (the container)
height
Number
The height of the render viewport
Default: 600
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
The method used to render values to the screen (either webgl, or canvas)
Default: RENDERER.AUTO
stage
PIXI.Stage
Raw PIXI.stage instance, the root of all things in the scene graph
timings
Object
Holds timing data for the previous loop
transparent
Boolean
Whether the canvas has a transparent background or not
Default: false
width
Number
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
NumberThe number of seconds passed since the last tick call (delta time)