Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Game

A base class for a game.

constructor

Hierarchy

  • Game

Index

Constructors

constructor

  • new Game(args?: any): Game
  • Parameters

    • Optional args: any

    Returns Game

Properties

Private _fpsMsg

_fpsMsg: any

Private _gameTimer

_gameTimer: any

_interval

_interval: number

_scale

_scale: number

Private _statusMessage

_statusMessage: any

Private _statusMessageAlpha

_statusMessageAlpha: any

Private _statusMessageColor

_statusMessageColor: any

Private _statusMessageTime

_statusMessageTime: any

_targetFps

_targetFps: number

assets

assets: AssetLoader

audio

canvas

canvas: HTMLCanvasElement

clearScreenColor

clearScreenColor: string

fpsColor

fpsColor: string

frames

frames: number

inputManager

inputManager: InputManager

lastTime

lastTime: number

paused

paused: boolean

Sets whether the game is paused. The game is still told to handle input, update itself and render. This is simply a flag that should be set whenever a "pause" screen is displayed. It stops the "in-game timer" until the game is unpaused.

param

Whether the game should be paused.

playTime

playTime: number

Returns the length of time the game has been played so far. This is "playable time;" that is, time in which the user is playing, and the game is not paused or in a "not updating" state (such as the main frame not having focus).

returns

The amount of time the game has been played, in milliseconds.

see

resetPlayTime

showFps

showFps: boolean

state

state: State

statusMessageRGB

statusMessageRGB: string

timer

timer: Timer

Methods

Private _renderFps

  • _renderFps(ctx: any): any
  • Parameters

    • ctx: any

    Returns any

Private _renderStatusMessage

  • _renderStatusMessage(ctx: any): any
  • Parameters

    • ctx: any

    Returns any

Private _tick

  • _tick(): any
  • Returns any

clearScreen

  • clearScreen(clearScreenColor?: string): void
  • Clears the screen.

    Parameters

    • Optional clearScreenColor: string

      The color to clear the screen with. If unspecified, this.clearScreenColor is used.

    Returns void

getHeight

  • getHeight(): number
  • Returns number

getWidth

  • getWidth(): number
  • Returns number

randomInt

  • randomInt(max: number): number
  • Returns a random number between 0 and number, exclusive.

    Parameters

    • max: number

      The upper bound, exclusive.

    Returns number

    The random number.

render

  • render(): void
  • Returns void

resetPlayTime

  • resetPlayTime(): void
  • Resets the "playtime in milliseconds" timer back to 0.

    see

    playTimeMillis

    Returns void

setState

  • setState(state: State): void
  • Parameters

    Returns void

setStatusMessage

  • setStatusMessage(message: string): void
  • Parameters

    • message: string

    Returns void

start

  • start(): void
  • Starts the game loop.

    Returns void

toggleMuted

  • toggleMuted(): boolean
  • Returns boolean

toggleShowFps

  • toggleShowFps(): void
  • Returns void

update

  • update(): void
  • Called during each tick to update game logic. The default implementation checks for a shortcut key to toggle the FPS display before delegating to the current game state. Subclasses can override, but typically update logic is handled by game states.

    Returns void

Generated using TypeDoc