Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Loader

The loader is an easy way to preload all the required assets for your game.
You can use it from the load() method of your Game class.
It can also be used while the game is running to load assets on the fly.

Hierarchy

  • Loader

Index

Properties

Static basePath

basePath: string = "."

The base path to the assets directory.

Methods

Static _init

  • _init(game: Game): void
  • Used internally to preload the game and its assets.

    Parameters

    • game: Game

      The game instance.

    Returns void

Static audio

  • audio(fileName: string): HTMLAudioElement | null
  • Get a audio that was loaded.
    If the audio was loaded on the fly, it may not be ready yet! You can check whether the file was loaded or not using the loaded() method.

    Parameters

    • fileName: string

      The name of the file to get.

    Returns HTMLAudioElement | null

    The audio file, or null if the audio was not loaded using loadAudio().

Static get

  • get(fileName: string): HTMLImageElement | HTMLAudioElement | HTMLVideoElement | any | null
  • Get a file from the loader.
    If the file was loaded on the fly, it may not be ready yet! You can check whether the file was loaded or not using the loaded() method.

    Parameters

    • fileName: string

      The name of the file to get.

    Returns HTMLImageElement | HTMLAudioElement | HTMLVideoElement | any | null

    The file, or null if the Loader does not contain the specified file.

Static image

  • image(fileName: string): HTMLImageElement | null
  • Get an image that was loaded.
    If the image was loaded on the fly, it may not be ready yet! You can check whether the file was loaded or not using the loaded() method.

    Parameters

    • fileName: string

      The name of the file to get.

    Returns HTMLImageElement | null

    The image file, or null if the image was not loaded using loadImage().

Static json

  • json(fileName: string): any | null
  • Get a JSON file that was loaded.
    If the JSON file was loaded on the fly, it may not be ready yet! You can check whether the file was loaded or not using the loaded() method.

    Parameters

    • fileName: string

      The name of the file to get.

    Returns any | null

    The parsed JSON file, or null if the JSON file was not loaded using loadJSON().

Static loadAudio

  • loadAudio(fileName: string, filePath: string): void
  • Load an audio file.
    If the file can't be loaded, the game won't start and a message will be logged to the console.

    Parameters

    • fileName: string

      The name to save this file as in the loader.

    • filePath: string

      The path to the file to load.

    Returns void

Static loadImage

  • loadImage(fileName: string, filePath: string): void
  • Load an image file.
    If the file can't be loaded, the game won't start and a message will be logged to the console.

    Parameters

    • fileName: string

      The name to save this file as in the loader.

    • filePath: string

      The path to the file to load.

    Returns void

Static loadJSON

  • loadJSON(fileName: string, filePath: string): void
  • Load a json file.
    If the file can't be loaded, the game won't start and a message will be logged to the console.

    Parameters

    • fileName: string

      The name to save this file as in the loader.

    • filePath: string

      The path to the file to load.

    Returns void

Static loadVideo

  • loadVideo(fileName: string, filePath: string): void
  • Load a video file.
    If the file can't be loaded, the game won't start and a message will be logged to the console.

    Parameters

    • fileName: string

      The name to save this file as in the loader.

    • filePath: string

      The path to the file to load.

    Returns void

Static loaded

  • loaded(fileName: string): boolean
  • Check whether a file is ready to be used or not.

    Parameters

    • fileName: string

      The file to check.

    Returns boolean

Static video

  • video(fileName: string): HTMLVideoElement | null
  • Get a video that was loaded.
    If the video was loaded on the fly, it may not be ready yet! You can check whether the file was loaded or not using the loaded() method.

    Parameters

    • fileName: string

      The name of the file to get.

    Returns HTMLVideoElement | null

    The video file, or null if the video was not loaded using loadVideo().

Generated using TypeDoc