Skip to content

@vaguevoid/fiasco / textureAssetManager / TextureAssetManager

Class: TextureAssetManager

Defined in: src/textureAssetManager.ts:84

The TextureAssetManager is used for loading textures into the engine. It is available directly on GpuInterface.

ts
import { GpuInterface } from '@vaguevoid/fiasco'

function system(gpuInterface: GpuInterface) {
  const texture = gpuInterface.textureAssetManager.loadTexture(...)
}

Methods

areIdsLoaded()

areIdsLoaded(ids): boolean

Defined in: src/textureAssetManager.ts:135

Check if certain texture id's are all loaded or not.

Parameters

ids

TextureId[]

An Array of TextureId's to check if loaded or not.

Returns

boolean

true if all texture ids are loaded.


getTextureById()

getTextureById(id): undefined | Texture

Defined in: src/textureAssetManager.ts:234

Get information about a given texture.

ts
import { GpuInterface, TextureRender, Query } from '@vaguevoid/fiasco'

function system(gpuInterface: GpuInterface, textureRenders: Query<[TextureRender]>) {
  for (const [textureRender] of textureRenders) {
    const texture = gpuInterface.textureAssetManager.getTextureById(textureRender.textureId)

    if (!texture) { continue }

    if (texture.kind === 'loaded') {
      // ...
    } else if (texture.kind === 'failed') {
      // ...
    } else if (texture.kind === 'pending') {
      // ...
    } else if (texture.kind === 'engine') {
      // ...
    }
  }
}

Parameters

id

TextureId

The texture id to receive information about.

Returns

undefined | Texture

A Texture object or undefined if no texture exists.


isIdLoaded()

isIdLoaded(id): boolean

Defined in: src/textureAssetManager.ts:144

Check if a certain texture id is loaded or not.

Parameters

id

TextureId

Returns

boolean

true if the texture is loaded.


loadTexture()

loadTexture(newTextureEventWriter, texturePath, insertInAtlas): undefined | PendingTexture

Defined in: src/textureAssetManager.ts:175

Load a texture into the engine.

ts
import { GpuInterface, EventWriter, Events, assert } from '@vaguevoid/fiasco'
import Sailboat from './assets/sailboat.png'
import Components from '../.fiasco/generated'

function system(gpuInterface: GpuInterface, newTexureEventWriter: EventWriter<Events.Graphics.NewTexture>) {
  const texture = gpuInterface.textureAssetManager.loadTexture(newTexureEventWriter, Sailboat)
  assert(texture)

  engine.spawn([
    // ...
    new Components.TextureRender({
      textureId: texture.id,
      visible: true
    })
  ])
}

Parameters

newTextureEventWriter

EventWriter<NewTexture>

A reference to an EventWriter<Events.Graphics.NewTexture>.

texturePath

string

A full texture path to a texture file.

insertInAtlas

boolean = false

If the texture should be inserted into an atlas.

Returns

undefined | PendingTexture

A PendingTexture object.


missingTextureId()

missingTextureId(): TextureId

Defined in: src/textureAssetManager.ts:126

The value of the default missing texture.

ts
import { GpuInterface } from '@vaguevoid/fiasco'

function system(gpuInterface: GpuInterface) {
  const id = gpuInterface.textureAssetManager.missingTextureId()
  console.log(id)
}

Returns

TextureId

A texture id representing a missing texture.


whiteTextureId()

whiteTextureId(): TextureId

Defined in: src/textureAssetManager.ts:108

The value of the default white texture.

ts
import { GpuInterface } from '@vaguevoid/fiasco'

function system(gpuInterface: GpuInterface) {
  const id = gpuInterface.textureAssetManager.whiteTextureId()
  console.log(id)
}

Returns

TextureId

A texture id representing white.