Skip to content
Braidon edited this page Sep 7, 2024 · 1 revision

class Game

Properties

Public

  • canvas : HTMLCanvasElement
    • The current canvas of the Game.
    • public, but shouldn't really be touched.
  • audioElement: HTMLAudioElement
    • The current audio element of the Game.
    • public, but shouldn't really be touched.
  • graphicsContext : Graphics
    • The Graphics instance, handles drawing and stuff.
  • audio : CattailAudio
    • The CattailAudio instance, handles audio and stuff.
  • entites : Array<GameObject>
    • An array of GameObjects that represent all of the entites currently having their logic run.
  • fps : number = 1000/60
    • Practically useless, used to determine deltatime, but isn't deltatime supposed to remain constant regardless of FPS?
  • currentLoop : number
    • This isn't even used.
  • backgroundImage: Sprite
    • Represents the background image of the current canvas.

Static

  • deltaTime : number;
    • It's delta-time, what else is there to say?
  • NullDrawable : Drawable;
    • If you want a purely logic GameObject, then assign this so it doesn't draw anything. Null won't work.

Private

  • context : CanvasRenderingContext2D
    • It's the rendering context for the current canvas.

Methods

  • constructor(size?: Vector2, backgroundColour?:Colour) : Game
    • Creates a new Game instance.
    • You can have multiple, but why?
    • Params:
      • size : Vector2 (optional): Determines the size of the game's canvas. If not specified, defaults to the size of the current window.
      • backgroundColour : Colour (optional): Specifies the colour of the canvas. If not specified, then defaults to white.

Public

  • setBackgroundImage(imageUrl: string) : void
    • Sets the background image of the game, the background image is a sprite, but it is always drawn in the very back.
    • Params:
      • imageUrl : string: the url to the image to be set as background.
  • addEntity(entity: GameObject) : void
    • Adds the specified GameObject to the list of simulated entities.
    • Params:
      • entity: GameObject: The game object to be added to the entities list.
  • run() : void
    • Runs the game.
    • In order:
      • calculates deltaTime
      • updates all entities
      • clears the canvas
      • draws the background
      • draws from the drawlist
      • requests the next animation frame

Clone this wiki locally