TextureAtlasBuilder

TextureAtlasBuilder

new

A utility class which dynamically builds a TextureAtlas by associating a unique identifier with each texture as it is added. If a texture with the same id is needed later, the existing index is returned, rather than adding multiple copies of the same texture.

See:
Source:

Methods

Checks the atlas for a texture with the supplied id, if the id does not exist, the supplied callback is triggered to create it. In either case, once the image is in the atlas, the second supplied callback is triggered with its index.

This function is useful for dynamically generated textures that are shared across many billboards. Only the first billboard will actually create the texture while subsequent billboards will re-use the existing one.

Parameters:
Name Type Description
id String The id of the image to add to the atlas.
getImageCallback Function A function which takes two parameters; first the id of the image to retrieve and second, a function to call when the image is ready. The function takes the image as its only parameter.
textureAvailableCallback Function A function taking the image index as it's only parameter.

Retrieves the image from the specified url and adds it to the atlas. The supplied callback is triggered with the index of the texture. If the url is already in the atlas, the atlas is unchanged and the callback is triggered immediately with the existing index.

Parameters:
Name Type Description
url String The url of the image to add to the atlas.
textureAvailableCallback Function A function taking the image index as it's only parameter.