Skip to main content

Class: Loader

An asset loader that can load textures and audio files. This class is used internally by the world and can be accessed via World.loader.

Properties​

audioBuffers​

• audioBuffers: Map<string, AudioBuffer>

A map of all audios loaded by Voxelize.


images​

• images: Map<string, HTMLImageElement | HTMLImageElement[]>


progress​

• progress: number = 0

The progress at which Loader has loaded, zero to one.


textureLoader​

• textureLoader: TextureLoader

The internal texture loader used by the loader.


textures​

• textures: Map<string, Texture<unknown>>

A map of all textures loaded by Voxelize.

Methods​

dispose​

▸ dispose(): void

Release everything the loader holds: the pending first-click audio gate, cached textures and images, and the decoded audio. The world calls this from its own dispose.

Returns​

void


getGifTexture​

▸ getGifTexture(source): Texture<unknown>[]

Get a loaded gif texture with this function.

Parameters​

NameTypeDescription
sourcestringThe source to the texture file loaded from.

Returns​

Texture<unknown>[]

A list of textures for each frame of the gif.


getTexture​

▸ getTexture(source): Texture<unknown>

Get a loaded texture by its source.

Parameters​

NameTypeDescription
sourcestringThe source to the texture file to load from.

Returns​

Texture<unknown>

A texture instance loaded from the source.


load​

▸ load(): Promise<void>

Load all assets other than the textures. Called internally by the world. This can be used to ensure that a function runs after all assets are loaded.

Returns​

Promise<void>

A promise that resolves when all assets are loaded.

Example

world.loader.load().then(() => {});

loadAudioBuffer​

▸ loadAudioBuffer(source, onLoaded?): Promise<AudioBuffer>

Add an audio file to be loaded from.

Parameters​

NameTypeDescription
sourcestringThe source to the audio file to load from.
onLoaded?(buffer: AudioBuffer) => voidA callback to run when the audio is loaded.

Returns​

Promise<AudioBuffer>


loadGifImages​

▸ loadGifImages(source, onLoaded?): Promise<HTMLImageElement[]>

Parameters​

NameType
sourcestring
onLoaded?(images: HTMLImageElement[]) => void

Returns​

Promise<HTMLImageElement[]>


loadImage​

▸ loadImage(source, onLoaded?): Promise<HTMLImageElement>

Parameters​

NameType
sourcestring
onLoaded?(image: HTMLImageElement) => void

Returns​

Promise<HTMLImageElement>


loadTexture​

▸ loadTexture(source, onLoaded?): Promise<Texture<unknown>>

Parameters​

NameType
sourcestring
onLoaded?(texture: Texture<unknown>) => void

Returns​

Promise<Texture<unknown>>