Provides loading and managing of textures.
This object keeps a map of requested textures by name in order to avoid duplicates. It also provides a default texture for those cases where the required one is missing or not yet loaded.
Loading of textures is an asynchronous operation. The TextureInstance objects can be used to automatically update references when the texture is downloaded. Using Scene.load() will automatically update textures.
Remapping functionality is also supported by the manager.
Some default procedural textures are provided by the manager:
Required scripts
The TextureManager object requires:
/*{{ javascript("jslib/texturemanager.js") }}*/
/*{{ javascript("jslib/observer.js") }}*/
/*{{ javascript("jslib/utilities.js") }}*/
Summary
Syntax
var textureManager = TextureManager.create(graphicsDevice, requestHandler, defaultTexture, errorCallback);
Summary
Requests loading of a texture by path.
Syntax
var onload = function onloadFn(textureInstance) {};
var texture = textureManager.load(path, nomipmaps, onload);
Returns the requested Texture if already loaded, the default texture otherwise. The callback function is called with the loaded Texture as an argument.
Summary
Adds a procedural texture to the manager.
Syntax
textureManager.add(name, texture);
Summary
Loads a texture archive.
If a texture named in the archive is already resident it will not be replaced.
Syntax
var onTextureLoaded = function onloadFn(texture) {};
var onArchiveLoaded = function onloadFn(success) {};
textureManager.loadArchive(path, nomipmaps, onTextureLoaded, onArchiveLoaded);
Supports is TAR files only.
Summary
Removes a loaded archive and removes all the textures the archive loaded.
Only textures actually loaded by the archive are unloaded, textures that are in the file archive but were already resident at load time will not be removed.
Syntax
textureManager.removeArchive(path);
Summary
Returns true if an archive is not pending.
Syntax
if (textureManager.isArchiveLoaded(path))
{
noMoreWaiting();
}
Summary
Returns the loaded texture stored with the given path or name.
Syntax
var texture = textureManager.get(path);
Returns the default texture if the required one is missing or not yet loaded.
Summary
Returns the TextureInstance stored with the given path or name.
Syntax
var textureInstance = textureManager.getInstance(path);
Returns a TextureInstance object.
Summary
Alias one texture to another name.
Syntax
textureManager.map(alias, name);
Summary
Deletes the texture stored with the given path or name.
Syntax
textureManager.remove(path);
Summary
Reloads the texture stored with the given path or name. Useful when the texture has been updated on the server and the application wants to retrieve the new one. The reloading of the texture will be done asynchronously.
Syntax
textureManager.reload(path);
Summary
Reloads all the stored textures. Useful when many textures have been updated on the server and the application wants to retrieve the new ones.
This operation may take a long time to complete. The reloading of the texture will be done asynchronously.
Syntax
textureManager.reloadAll();
Summary
Returns the number of textures requested but still to be loaded.
Syntax
var numPendingTextures = textureManager.getNumPendingTextures();
if (numPendingTextures)
{
keepWaiting();
}
Summary
Returns true if a texture is not pending.
Syntax
if (textureManager.isTextureLoaded(path))
{
noMoreWaiting();
}
Summary
Returns true if a texture is missing.
Syntax
if (textureManager.isTextureMissing(path))
{
errorWhilstLoading();
}
Summary
Enables remapping of loading paths.
The remapping only affects the loading URL, the texture will be stored under the original name it was requested with.
Syntax
textureManager.setPathRemapping(mappingDictionary, prefix);
// example usage:
var mappingTableReceived = function mappingTableReceivedFn(mappingTable)
{
textureManager.setPathRemapping(mappingTable.urlMapping, mappingTable.assetPrefix);
};
mappingTable = TurbulenzServices.createMappingTable(gameSession,
mappingTableReceived);
Both arguments for setPathRemapping are properties on the MappingTable object.
Summary
Releases the TextureManager object and all the resources it allocated; the object and the textures it referenced will be invalid after the method is called.
Syntax
textureManager.destroy();