Options
All
  • Public
  • Public/Protected
  • All
Menu
classdesc

A class that loads images and other assets

description

The Loader Class. Preloading and loading is handled here

since

1.0.0-beta

Hierarchy

  • Loader

Index

Constructors

constructor

Properties

audioStack

audioStack: StackItem<HTMLAudioElement>[]
memberof

Loader

description

An array of loaded Audio elements

since

2.0.0

fontStack

fontStack: StackItem<FontFace>[]
memberof

Loader

description

An array of loaded FontFaces

since

2.0.0

game

game: Game
memberof

Loader

description

Game instance

since

1.0.0-beta

htmlStack

htmlStack: StackItem<Document>[]
memberof

Loader

description

An array of loaded HTML Documents

since

2.0.0

jsonStack

jsonStack: StackItem<Record<string, unknown>>[]
memberof

Loader

description

An array of loaded JSON files

since

2.0.0

scene

scene: Scene
memberof

Loader

description

Scene instance

since

2.0.0

textureStack

textureStack: TextureStackItem<TextureBase<"image">>[]
memberof

Loader

description

An array of loaded Textures

since

2.0.0

xmlStack

xmlStack: StackItem<Document>[]
memberof

Loader

description

An array of loaded XML Documents

since

2.0.0

Methods

loadAudio

  • loadAudio(pathOrURL: string, key: string, mimeType?: string): Promise<HTMLAudioElement>
  • memberof

    Loader

    description

    Loads an Audio file and adds it to the audioStack

    since

    2.0.0

    Parameters

    • pathOrURL: string

      Path to the file or the URL

    • key: string

      Key of the file to use to save it as

    • mimeType: string = 'audio/mp3'

    Returns Promise<HTMLAudioElement>

loadFont

  • loadFont(fontFamily: string, pathOrURL: string, key: string, descriptors?: FontFaceDescriptors): Promise<FontFace>
  • memberof

    Loader

    description

    Loads a font and adds it to the fontStack

    since

    2.0.0

    Parameters

    • fontFamily: string

      Font Family

    • pathOrURL: string

      Path to the file or the URL

    • key: string

      Key of the file to use to save it as

    • Optional descriptors: FontFaceDescriptors

    Returns Promise<FontFace>

loadHTML

  • loadHTML(pathOrURL: string, key: string): Promise<Document>
  • memberof

    Loader

    description

    Loads a HTML file and adds it to the htmlStack

    since

    2.0.0

    Parameters

    • pathOrURL: string

      Path to the file or the URL

    • key: string

      Key of the file to use to save it as

    Returns Promise<Document>

loadJSON

  • loadJSON(pathOrURL: string, key: string): Promise<Record<string, unknown>>
  • memberof

    Loader

    description

    Loads a JSON file and adds it to the jsonStack, caches it if it does not already exist

    since

    2.0.0

    Parameters

    • pathOrURL: string

      Path to the file or the URL

    • key: string

      Key of the file to use to save it as

    Returns Promise<Record<string, unknown>>

loadTexture

  • loadTexture(pathOrURL: string, key: string, w: number, h: number): Promise<HTMLImageElement>
  • memberof

    Loader

    description

    Loads an image and creates a texture, caches it if it does not already exist in the cache (clear cache if texture does not update if you edit the image src)

    since

    2.0.0

    Parameters

    • pathOrURL: string

      Path to the file or the URL

    • key: string

      Key of the texture, used to load the texture in sprites

    • w: number

      Width of image

    • h: number

      Height of image

    Returns Promise<HTMLImageElement>

loadTextureAtlas

  • loadTextureAtlas(atlasKey: string, texturePathOrURL: string, jsonPathOrURL: string, textureKey: string, jsonKey: string, imageW: number, imageH: number): Promise<void>
  • Parameters

    • atlasKey: string
    • texturePathOrURL: string
    • jsonPathOrURL: string
    • textureKey: string
    • jsonKey: string
    • imageW: number
    • imageH: number

    Returns Promise<void>

loadTextureSheet

  • loadTextureSheet(pathOrURL: string, key: string, frameWidth: number, frameHeight: number, rows: number, cols: number): Promise<HTMLImageElement>
  • memberof

    Loader

    description

    Loads an image and creates a texture sheet, caches it if it does not already exist in the cache (clear cache if texture does not update if you edit the image src)

    since

    2.1.0

    Parameters

    • pathOrURL: string

      Path to the file or the URL

    • key: string

      Key of the texture, used to load the texture in sprites and spritesheet

    • frameWidth: number
    • frameHeight: number
    • rows: number
    • cols: number

    Returns Promise<HTMLImageElement>

loadXML

  • loadXML(pathOrURL: string, key: string): Promise<Document>
  • memberof

    Loader

    description

    Loads a XML file and adds it to the xmlStack

    since

    2.0.0

    Parameters

    • pathOrURL: string

      Path to the file or the URL

    • key: string

      Key of the file to use to save it as

    Returns Promise<Document>

Protected saveCache

  • saveCache(prefix: string, key: string, value: string): Promise<void>

Protected tryCache

  • tryCache(prefix: string, key: string): Promise<undefined | null | string>

Generated using TypeDoc