Extend to implement custom resources.

The loader-id is the used to ensure that we can load the same assets out of different contexts. For each loader-id there can only be one loader.

Loaders can be build for specific game needs.

Overwrite unload to release GPU objects.

Hierarchy

Constructors

Methods

  • Implement here your custom loading and parsing parts.

    Use this.manager to access the resource manager and use existing loaders to get things done fast and easy.

    // Example:
    // 1. uses TextLoader to load the json raw string data
    // 2. parses the raw text to json
    load(path:string):Promise<any> {
    return this.manager.request<string>(`text:${path}`)
    .then(jsonStr => {
    try {
    const json = JSON.parse(jsonStr);
    return Promise.resolve(json);
    }
    catch(err) {
    throw new Error(`Cannot parse json from ${path}. Reason: ${(err as any).message}`);
    }
    });
    }

    Parameters

    • path: string

      is only the path part. There is NO loader-id here.

    • loader: any

    Returns Promise<any>

  • Overwrite this function to be able to remove foreign memory objects.

    Some resources, like GPU objects might contain foreign memory objects that should be removed alongside with the CPU memory.

    If all goes well this is never called during loading itself. One can always assume that the resource is fully loaded.


    There is also FinalizationRegistry but it might introduce additional load on the CPU/GPU during normal gameplay.

    Parameters

    • path: string
    • resourceObj: any

    Returns void | Promise<undefined>

Generated using TypeDoc