@bloopjs/toodle / textures/AssetManager / AssetManager
Class: AssetManager
Defined in: textures/AssetManager.ts:33
Constructors
Constructor
new AssetManager(
backend,options):AssetManager
Defined in: textures/AssetManager.ts:41
Parameters
backend
options
AssetManagerOptions = {}
Returns
AssetManager
Properties
bundles
readonlybundles:Bundles
Defined in: textures/AssetManager.ts:34
extra
extra:
object
Defined in: textures/AssetManager.ts:465
Advanced and niche features
getAtlasCoords()
getAtlasCoords: (
id) =>AtlasCoords[]
Get the atlas coordinates for a texture.
Parameters
id
string
The id of the texture to get the atlas coordinates for
Returns
An array of the atlas coordinates for the texture
getAtlasUsage()
getAtlasUsage: () =>
object
Get diagnostics on texture atlas usage
Returns
Usage stats for texture atlases
available
available:
number
The number of texture atlases that are currently unused and available to load textures into.
total
total:
number=totalLayers
The total number of texture atlases that can be loaded.
used
used:
number
The number of texture atlases that are currently in use.
getLoadedBundleIds()
getLoadedBundleIds: () =>
string[]
Returns
string[]
getRegisteredBundleIds()
getRegisteredBundleIds: () =>
string[]
Returns
string[]
getTextureOffset()
getTextureOffset: (
id) =>Vec2
Get the texture default offset
Parameters
id
string
The id of the texture to get the atlas coordinates for
Returns
Point of the texture's associated X,Y offset
loadAtlas()
loadAtlas: (
atlas) =>Promise<number>
Load a texture atlas from a CpuTextureAtlas.
Parameters
atlas
The texture atlas to load
Returns
Promise<number>
The index of the atlas
nextAvailableAtlasIndex()
nextAvailableAtlasIndex: () =>
number
Consume the next available atlas index.
Returns
number
setAtlasCoords()
setAtlasCoords: (
id,coords) =>void
Set the atlas coordinates for a texture.
This should not be necessary for most use cases. This allows for UV precision
Parameters
id
string
The id of the texture to set the atlas coordinates for
coords
The atlas coordinates to set
Returns
void
unloadAtlas()
unloadAtlas: (
atlasIndex) =>Promise<void>
Unload an atlas from the texture atlas.
Parameters
atlasIndex
number
The index of the atlas to unload
Returns
Promise<void>
Accessors
atlasId
Get Signature
get atlasId():
string
Defined in: textures/AssetManager.ts:66
Get the atlas ID this asset manager uses.
Returns
string
atlasSize
Get Signature
get atlasSize():
Size
Defined in: textures/AssetManager.ts:81
Get the atlas dimensions
Returns
textureAtlas
Get Signature
get textureAtlas():
GPUTexture
Defined in: textures/AssetManager.ts:74
Get the GPU texture atlas. For WebGPU, returns GPUTexture.
Deprecated
Access via backend.getTextureAtlas(atlasId).handle instead
Returns
GPUTexture
textureIds
Get Signature
get textureIds():
string[]
Defined in: textures/AssetManager.ts:146
A read-only array of all currently loaded texture ids.
Returns
string[]
textures
Get Signature
get textures():
ReadonlyMap<string,AtlasCoords[]>
Defined in: textures/AssetManager.ts:139
A read-only map of all currently loaded textures.
Returns
ReadonlyMap<string, AtlasCoords[]>
Methods
destroy()
destroy():
void
Defined in: textures/AssetManager.ts:616
Destroy the texture atlas. This should free up ~4gb of gpu memory (and make all draw calls fail)
Returns
void
getCroppedSize()
getCroppedSize(
id):Size
Defined in: textures/AssetManager.ts:108
Dimensions of a loaded texture, cropped to a minimal bounding box.
Parameters
id
string
The id of the texture to get the size of
Returns
The size of the texture
getFont()
getFont(
id):TextShader
Defined in: textures/AssetManager.ts:353
Parameters
id
string
Returns
getSize()
getSize(
id):Size
Defined in: textures/AssetManager.ts:92
True dimensions of a loaded texture, prior to any transparent pixel cropping.
Parameters
id
string
The id of the texture to get the size of
Returns
The size of the texture
isCropped()
isCropped(
id):boolean
Defined in: textures/AssetManager.ts:126
Whether the texture has been cropped for extra transparency.
Parameters
id
string
The id of the texture to be checked
Returns
boolean
Whether the image has been cropped (i.e. if it has uvScaledCropped)
loadBundle()
loadBundle(
bundleId):Promise<void>
Defined in: textures/AssetManager.ts:266
Load a bundle of textures to the gpu
See: https://toodle.gg/f849595b3ed13fc956fc1459a5cb5f0228f9d259/examples/texture-bundles.html
Parameters
bundleId
string
Returns
Promise<void>
loadFont()
loadFont(
id,url,fallbackCharacter):Promise<string>
Defined in: textures/AssetManager.ts:321
Load a font to the gpu
Parameters
id
string
The id of the font to load
url
URL
The url of the font to load
fallbackCharacter
string = "_"
The character to use as a fallback if the font does not contain a character to be rendererd
Returns
Promise<string>
Throws
Error if using WebGL backend (fonts not supported in WebGL mode)
loadTexture()
loadTexture(
id,url,options?):Promise<{coords:AtlasCoords;id:string; }>
Defined in: textures/AssetManager.ts:185
Debug method to load a single texture.
Parameters
id
string
ID used to name the texture
url
URL or ImageBitmap target for the image
URL | ImageBitmap
options?
Partial<TextureBundleOpts>
LoadingOptions used to modify the loading process
Note: this will consume one texture atlas per texture. For more efficient loading of multiple textures, consider loadBundle
Returns
Promise<{ coords: AtlasCoords; id: string; }>
Throws
Error if using WebGL backend (use registerBundle instead)
loadTextures()
loadTextures(
opts):Promise<void>
Defined in: textures/AssetManager.ts:167
Debug method to load a set of textures from a record of URLS.
Parameters
opts
Record<string, URL>
Returns
Promise<void>
Example
await toodle.assets.loadTextures({
"myImage": new URL("assets/image.png", "https://mywebsite.com"),
});Deprecated
use registerBundle instead. or loadTexture for debugging
registerBundle()
registerBundle(
bundleId,opts):Promise<string>
Defined in: textures/AssetManager.ts:244
Register a bundle of textures.
Parameters
bundleId
string
ID used to name the bundle
opts
TextureBundleOpts | AtlasBundleOpts
Returns
Promise<string>
unloadBundle()
unloadBundle(
bundleId):Promise<void>
Defined in: textures/AssetManager.ts:294
Unload a bundle of textures from the gpu - this marks the gpu-side texture atlas as available for future texture loading.
Parameters
bundleId
string
The id of the bundle to unload
Returns
Promise<void>
validateTextureReference()
validateTextureReference(
node):void
Defined in: textures/AssetManager.ts:362
Parameters
node
Returns
void