Table Of Contents

Previous topic

21.49. The TextureEffects Object

Next topic

21.51. The TextureManager Object

This Page

21.50. The TextureInstance Object

These are usually created by a TextureManager and accessed via TextureManager.getInstance(). Its role is to provide a proxy to a texture and provides a notification mechanism to allow other code to update texture references, for example when a texture is downloaded.

The TextureInstance are reference counted.

Required scripts

The TextureInstance object requires:

/*{{ javascript("jslib/texturemanager.js") }}*/
/*{{ javascript("jslib/observer.js") }}*/
/*{{ javascript("jslib/utilities.js") }}*/

21.50.1. Constructor

21.50.1.1. create

Summary

Creates and returns a TextureInstance object.

Syntax

var textureInstance = TextureInstance.create(name, texture);
name
A JavaScript string. The name of the texture.
texture
A Texture object.

21.50.2. Methods

21.50.2.1. setTexture

Summary

Set the texture object associated with the TextureInstance. This will notify any observer function registered with subscribeTextureChanged.

Syntax

textureInstance.setTexture(texture);
texture
A Texture object.

21.50.2.2. getTexture

Summary

Get the texture object associated with the TextureInstance.

Syntax

var texture = textureInstance.getTexture();

Returns a Texture object.

21.50.2.3. subscribeTextureChanged

Summary

Register a function object to call when the texture changes.

Syntax

textureInstance.subscribeTextureChanged(textureChangedCallback);
textureChangedCallback
A callback function which takes a TextureInstance object as an argument.

21.50.2.4. subscribeTextureChanged

Summary

Unregistered a function object previously registered with subscribeTextureChanged.

Syntax

textureInstance.unsubscribeTextureChanged(textureChangedCallback);
textureChangedCallback
A callback function.

21.50.2.5. destroy

Summary

Free the resources attached to the object. This is normally called automatically when the reference count drops to 0.

Syntax

textureInstance.destroy();