TextureLoader

Decodes images with one roTextureManager. On a Roku the decode runs off the BrightScript thread, so a large image doesn't stall a frame the way CreateObject("roBitmap", path) does. Bitmaps it makes can't be drawn into before Roku OS 16. The game owns one (game.getTextureLoader()), and BGE.AssetLoader.loadBitmap() uses it.

Properties

  • timeoutMs (integer) — How long a request may take before getResult() gives up on it

Constructor

new TextureLoader(): TextureLoader

Instance Methods

isAvailable(): boolean

Whether this device has a texture manager to decode with.

Returns

  • boolean

request( path: string, width?: integer, height?: integer, smooth?: boolean, ): roTextureRequest

Starts decoding an image file.

Parameters

  • path (string) — a local image file (pkg:, tmp:, cachefs:, ...)
  • width (integer, optional, default: 0) — resize to this width while decoding (needs height too)
  • height (integer, optional, default: 0) — resize to this height while decoding
  • smooth (boolean, optional, default: true) — false resizes with nearest neighbour (crisp pixel art)

Returns

  • roTextureRequest — pass it to getResult() each frame

getResult(textureRequest: roTextureRequest): BGE.TextureResult

The result of a request, once it has finished.

Parameters

  • textureRequest (roTextureRequest)

Returns

  • BGE.TextureResult — invalid while still decoding; not ok (and timedOut) if it took longer than timeoutMs

cancel(textureRequest: roTextureRequest): void

Stops a request that hasn't finished.

Parameters

  • textureRequest (roTextureRequest)

Returns

  • void

unload(path: string): void

Drops the texture manager's copy of a file's bitmap, so its memory is freed once nothing else holds it, and the next request decodes the file again.

Parameters

  • path (string)

Returns

  • void