dacha
    Preparing search index...

    Class Assets

    The project assets.

    The engine creates an Asset for every entry in assets of the configuration. A MediaAsset gives its loaded file through MediaAsset.resource.

    const texture = this.assets.get(Texture, TEXTURE_ID)?.resource;
    
    Index
    • Holds assets for owner and loads the media among them.

      A second call by the same owner replaces what it holds, and assets that both sets share stay loaded. Pass add: true to keep what the owner holds and add to it.

      Call Assets.release when the owner no longer needs the assets. Do not pass a scene as the owner without add: true: that replaces what the engine holds for the scene.

      Parameters

      Returns Promise<void>

      async onSceneLoad() {
      await this.assets.acquire(this, { assets: [cutsceneId], templates: [bossId] });
      }

      onSceneDestroy() {
      this.assets.release(this);
      }
    • Makes sure that owner holds one asset, with the assets it references, and starts loading it if it is not loaded. It does not wait for the file. Does nothing when the owner already holds the asset, so you can call it every frame.

      Use it in a system that draws or plays an asset by an id that can change while the game runs. Pass the scene as the owner, and the asset unloads with the scene. To wait for the files, use Assets.acquire.

      Parameters

      • owner: string | object
      • id: string

      Returns void

      const map = this.assets.get(LevelMap, minimap.map);
      if (map && !map.resource) {
      this.assets.ensure(this.scene, minimap.map);
      }
    • Returns an asset by its id, or undefined when there is none.

      Parameters

      • id: string

      Returns Asset | undefined

    • Returns an asset of one class by its id, or undefined when there is none.

      Type Parameters

      Parameters

      Returns T | undefined

    • Checks if there is an asset with this id.

      Parameters

      • id: string

      Returns boolean

    • Drops what owner holds with Assets.acquire. An asset that no owner holds is unloaded.

      Parameters

      • owner: string | object

      Returns void