Shaku

Shaku JS

Back To Table of Content

Texture Asset

TextureAsset

A loadable texture asset. This asset type loads an image from URL or source, and turn it into a texture.

Kind: global class

textureAsset.image

Kind: instance property of TextureAsset

textureAsset.width

Kind: instance property of TextureAsset

textureAsset.height

Kind: instance property of TextureAsset

textureAsset._glTexture

Kind: instance property of TextureAsset

textureAsset.valid

Kind: instance property of TextureAsset

textureAsset.load(params) ⇒ Promise

Load the texture from it’s image URL.

Kind: instance method of TextureAsset
Returns: Promise - Promise to resolve when fully loaded.

Param Type Description
params \* Optional additional params. Possible values are: - generateMipMaps (default=false): if true, will generate mipmaps for this texture. - crossOrigin (default=undefined): if set, will set the crossOrigin property with this value. - flipY (default=false): if true, will flip texture on Y axis. - premultiplyAlpha (default=false): if true, will load texture with premultiply alpha flag set.

textureAsset.createRenderTarget(width, height, channels)

Create this texture as an empty render target.

Kind: instance method of TextureAsset

Param Type Description
width Number Texture width.
height Number Texture height.
channels Number Texture channels count. Defaults to 4 (RGBA).

textureAsset.fromImage(image, params)

Create texture from loaded image instance.

Kind: instance method of TextureAsset
See: TextureAsset.load for params.

Param Type Description
image Image Image to create texture from. Image must be loaded!
params \* Optional additional params. See load() for details.

textureAsset.create(source, params) ⇒ Promise

Create the texture from an image.

Kind: instance method of TextureAsset
Returns: Promise - Promise to resolve when asset is ready.
See: TextureAsset.load for params.

Param Type Description
source Image | String Image or Image source URL to create texture from.
params \* Optional additional params. See load() for details.

textureAsset.getPixel(x, y) ⇒ Color

Get pixel color from image. Note: this method is quite slow, if you need to perform multiple queries consider using getPixelsData() once to get all pixels data instead.

Kind: instance method of TextureAsset
Returns: Color - Pixel color.

Param Type Description
x Number Pixel X value.
y Number Pixel Y value.

textureAsset.getPixelsData([x], [y], [width], [height]) ⇒ Array.<Array.<Color>>

Get a 2D array with pixel colors.

Kind: instance method of TextureAsset
Returns: Array.<Array.<Color>> - A 2D array with all texture pixel colors.

Param Type Description
[x] Number Offset X in texture to get. Defaults to 0.
[y] Number Offset Y in texture to get. Defaults to 0.
[width] Number How many pixels to get on X axis. Defaults to texture width - x.
[height] Number How many pixels to get on Y axis. Defaults to texture height - y.

textureAsset.destroy()

Kind: instance method of TextureAsset