A Loader class which helps with loading video and image textures.

Properties

CACHE_TTL: number = ...

The duration in milliseconds for which a texture will remain cached

A global reference to the singleton texture loader

Accessors

  • get approximateTotalMemoryUsage(): number

    A public getter to expose the total approximate memory usage.

    Returns number

    The total usage in bytes.

Methods

  • Expire and unload assets from the cache which have not been used for more than CACHE_TTL milliseconds.

    Parameters

    • Optionaloptions: { exclude?: Set<string> } = {}
      • Optionalexclude?: Set<string>

        A set of source URLs to skip from eviction checks.

    Returns Promise<void>

  • Retrieve a texture or a sprite sheet from the assets cache

    Parameters

    • src: string

      The source URL

    Returns null | Spritesheet<ISpritesheetData> | BaseTexture<Resource, IAutoDetectOptions>

    The cached texture, a sprite sheet or null

  • Load an Array of provided source URL paths. Paths which begin with a special character "#" are ignored as texture references.

    Parameters

    • sources: string[]

      The source URLs to load

    • Optionaloptions: {
          clean?: boolean;
          displayProgress?: boolean;
          escape?: boolean;
          expireCache?: boolean;
          format?: string;
          localize?: boolean;
          maxConcurrent?: number;
          message?: string;
      } = {}

      Additional options which modify loading

      • Optionalclean?: boolean

        Whether to clean the provided message string as untrusted user input. No cleaning is applied if format is passed and escape is true or localize is true and format is not passed.

      • OptionaldisplayProgress?: boolean

        Display loading progress bar

      • Optionalescape?: boolean

        Whether to escape the values of format

      • OptionalexpireCache?: boolean

        Expire other cached textures?

      • Optionalformat?: string

        A mapping of formatting strings passed to Localization#format

      • Optionallocalize?: boolean

        Whether to localize the message content before displaying it

      • OptionalmaxConcurrent?: number

        The maximum number of textures that can be loaded concurrently.

      • Optionalmessage?: string

        The status message to display in the load bar

    Returns Promise<void>

    A Promise which resolves once all textures are loaded

  • Load a single texture or spritesheet on-demand from a given source URL path

    Parameters

    • src: string

      The source texture path to load

    Returns Promise<
        | null
        | Spritesheet<ISpritesheetData>
        | BaseTexture<Resource, IAutoDetectOptions>,
    >

    The loaded texture object

  • Add an image or a sprite sheet url to the assets cache. Include an approximate memory size in the stored data.

    Parameters

    • src: string

      The source URL.

    • asset: Spritesheet<ISpritesheetData> | BaseTexture<Resource, IAutoDetectOptions>

      The asset

    Returns void

  • Use the Fetch API to retrieve a resource and return a Blob instance for it.

    Parameters

    • src: string
    • Optionaloptions: { bustCache?: boolean } = {}

      Options to configure the loading behaviour.

      • OptionalbustCache?: boolean

        Append a cache-busting query parameter to the request.

    Returns Promise<Blob>

    A Blob containing the loaded data

  • Return a URL with a cache-busting query parameter appended.

    Parameters

    • src: string

      The source URL being attempted

    Returns string | boolean

    The new URL, or false on a failure.

  • Use the texture to create a cached mapping of pixel alpha and cache it. Cache the bounding box of non-transparent pixels for the un-rotated shape.

    Parameters

    • texture: Texture<Resource>

      The provided texture.

    • Optionalresolution: number = 1

      Resolution of the texture data output.

    Returns undefined | TextureAlphaData

    The texture data if the texture is valid, else undefined.

  • Check if a source has a text file extension.

    Parameters

    • src: string

      The source.

    Returns boolean

    If the source has a text extension or not.

  • Load all the textures which are required for a particular Scene.

    Parameters

    • scene: Scene

      The Scene to load

    • Optionaloptions: { additionalSources?: string[]; expireCache?: boolean; maxConcurrent?: number } = {}

      Additional options that configure texture loading

      • OptionaladditionalSources?: string[]

        Additional sources to load during canvas initialize

      • OptionalexpireCache?: boolean

        Destroy other expired textures

      • OptionalmaxConcurrent?: number

        The maximum number of textures that can be loaded concurrently

    Returns Promise<void>

  • Pin a source URL so it cannot be evicted.

    Parameters

    • src: string

      The source URL to pin

    Returns void

  • Unpin a source URL that was previously pinned.

    Parameters

    • src: string

      The source URL to unpin

    Returns void