@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
.
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
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.
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
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
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.
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
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.
import { GpuInterface } from '@vaguevoid/fiasco'
function system(gpuInterface: GpuInterface) {
const id = gpuInterface.textureAssetManager.missingTextureId()
console.log(id)
}
Returns
A texture id representing a missing texture.
whiteTextureId()
whiteTextureId():
TextureId
Defined in: src/textureAssetManager.ts:108
The value of the default white texture.
import { GpuInterface } from '@vaguevoid/fiasco'
function system(gpuInterface: GpuInterface) {
const id = gpuInterface.textureAssetManager.whiteTextureId()
console.log(id)
}
Returns
A texture id representing white.