Options
All
  • Public
  • Public/Protected
  • All
Menu

Contains all aspects of a game.

Example

// This is a boring 'game'.
const game = new Game(640, 480)

game.run()

Hierarchy

  • Game

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • new Game(width: number, height: number, useWebGL?: boolean, container?: HTMLElement): Game
  • Initialize Game object.

    Parameters

    • width: number

      Width of the game screen.

    • height: number

      Height of the game screen.

    • Default value useWebGL: boolean = true

      Whether or not to render with WebGL. Falls back to canvas. Default is true.

    • Default value container: HTMLElement = document.body

      The element to append the canvas to. Default is document.body

    Returns Game

Properties

Static FPS

FPS: number = 60

Frames per second. Only updated if debug is true.

Static UPS

UPS: number = 60

Updates per second. Only updated if debug is true.

Static assets

assets: Assets = new Assets()

An Assets instance for loading all game assets.

Static debug

debug: boolean = false

Whether or not to enable debug display (shows FPS and UPS).

Accessors

canvas

  • get canvas(): HTMLCanvasElement
  • Gets the canvas element used by the renderer.

    Returns HTMLCanvasElement

height

  • get height(): number
  • Gets the height of the game screen.

    Returns number

scene

speed

  • get speed(): number
  • set speed(value: Speed | number): void

width

  • get width(): number
  • Gets the width of the game screen.

    Returns number

Methods

run

  • run(gameUpdate?: GameUpdate, clear?: boolean): void
  • Start the game loop.

    Parameters

    • Default value gameUpdate: GameUpdate = () => {}

      An update function to run for the game.

    • Default value clear: boolean = true

      Whether or not to clear the canvas between each update.

    Returns void

setScene

  • setScene(scene: Scene, fadeInSeconds?: number): void
  • Change to a new scene in the game.

    Parameters

    • scene: Scene

      The new scene to transition into.

    • Default value fadeInSeconds: number = 0.5

      Time in seconds for the transition.

    Returns void