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

#cacheTime: Map<any, {
    src: string;
    time: number;
}> = ...

Record the timestamps when each asset path is retrieved from cache.

Type declaration

  • src: string
  • time: number
#textureDataMap: WeakMap<BaseTexture, Map<string, TextureAlphaData>> = ...

A mapping of cached texture data

#retryString: string = ...

Create a fixed retry string to use for CORS retries.

#basisTranscoderInitialized: boolean = false

To know if the basis transcoder has been initialized

Methods

  • Load an Array of provided source URL paths

    Parameters

    • sources: string[]

      The source URLs to load

    • Optional options: {
          message: string;
          expireCache: boolean;
          maxConcurrent: number;
          displayProgress: boolean;
      } = {}

      Additional options which modify loading

      • message: string

        The status message to display in the load bar

      • expireCache: boolean

        Expire other cached textures?

      • maxConcurrent: number

        The maximum number of textures that can be loaded concurrently.

      • displayProgress: boolean

        Display loading progress 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<any>

    The loaded texture object

  • Add an image or a sprite sheet url to the assets cache.

    Parameters

    • src: string

      The source URL.

    • asset: any

      The asset

    Returns void

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

    Parameters

    • src: string

      The source URL

    Returns any

    The cached texture, a sprite sheet or undefined

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

    Returns Promise<void>

  • Initialize the basis transcoder for PIXI.Assets

    Returns Promise<any>

  • 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.

  • 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

      The provided texture.

    • Optional resolution: number = 1

      Resolution of the texture data output.

    Returns TextureAlphaData

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

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

    Parameters

    • scene: Scene

      The Scene to load

    • Optional options: {
          expireCache: boolean;
          additionalSources: boolean;
          maxConcurrent: number;
      } = {}

      Additional options that configure texture loading

      • expireCache: boolean

        Destroy other expired textures

      • additionalSources: boolean

        Additional sources to load during canvas initialize

      • maxConcurrent: number

        The maximum number of textures that can be loaded concurrently

    Returns Promise<void[]>

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

    Parameters

    • src: string
    • Optional options: {
          bustCache: boolean;
      } = {}

      Options to configure the loading behaviour.

      • bustCache: 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.

  • Private

    Log texture loading progress in the console and in the Scene loading bar

    Parameters

    • src: string

      The source URL being loaded

    • progress: object

      Loading progress

    Returns void

  • Private

    Log failed texture loading

    Parameters

    • src: string

      The source URL being loaded

    • progress: object

      Loading progress

    • error: Error

      The error which occurred

    Returns void