Engine API Reference
    Preparing search index...

    Class ResourceLoader

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

    Index

    Constructors

    Methods

    • Remove resource from cache.

      Parameters

      • url: string

        The URL of the resource.

      • type: string

        The type of resource.

      Returns void

    • Destroys the resource loader.

      Returns void

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

    • Get a ResourceHandler for a resource type.

      Parameters

      • type: string

        The name of the resource type that the handler is registered with.

      Returns undefined | ResourceHandler

      The registered handler, or undefined if the requested handler is not registered.

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

      • Optionalasset: Asset

        Optional asset that is passed into handler.

      • Optionaloptions: { bundlesFilter?: BundlesFilterCallback; bundlesIgnore?: boolean }

        Additional options for loading.

        • OptionalbundlesFilter?: 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.

        • OptionalbundlesIgnore?: boolean

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

      Returns void

      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.

    • Perform any operations on a resource, that requires a dependency on its asset data or any other asset data.

      Parameters

      Returns void

    • Remove a ResourceHandler for a resource type.

      Parameters

      • type: string

        The name of the type that the handler will be removed.

      Returns void