Load resource data, potentially from remote sources. Caches resource on load to prevent multiple requests. Add ResourceHandlers to handle different types of resources.

Constructors

Methods

  • Check cache for resource from a URL. If present, return the cached value.

    Parameters

    • url: string

      The URL of the resource to get from the cache.

    • type: string

      The type of the resource.

    Returns any

    The resource loaded from the cache.

  • Make a request for a resource from a remote URL. Parse the returned data using the handler for the specified type. When loaded and parsed, use the callback to return an instance of the resource.

    Parameters

    • url: string

      The URL of the resource to load.

    • type: string

      The type of resource expected.

    • callback: ResourceLoaderCallback

      The callback used when the resource is loaded or an error occurs. Passed (err, resource) where err is null if there are no errors.

    • Optional asset: Asset

      Optional asset that is passed into handler.

    • Optional options: {
          bundlesFilter: BundlesFilterCallback;
          bundlesIgnore: boolean;
      }

      Additional options for loading.

      • bundlesFilter: BundlesFilterCallback

        A callback that will be called when loading an asset that is contained in any of the bundles. It provides an array of bundles and will ensure asset is loaded from bundle returned from a callback. By default smallest filesize bundle is choosen.

      • bundlesIgnore: boolean

        If set to true, then asset will not try to load from a bundle. Defaults to false.

    Returns void

    Example

    app.loader.load("../path/to/texture.png", "texture", function (err, texture) {
    // use texture here
    });
  • Convert raw resource data into a resource instance. E.g. Take 3D model format JSON and return a Model.

    Parameters

    • type: string

      The type of resource.

    • data: any

      The raw resource data.

    Returns any

    The parsed resource data.