Skip to main content

Class: GradientTexture

texture/gradient.GradientTexture

Represents a texture with a gradient as it's image.

Hierarchy

Constructors

constructor

โ€ข new GradientTexture(type, dir, resolution, ...stops)

Creates a GradientTexture.

Before use the texture must be refreshed, this is done by calling the refresh() method on the texture.

Parameters

NameTypeDescription
typeGradientTypeThe type of gradient (linear, radial, etc)
dirGradientDirectionThe direction fo the gradient
resolutionnumberThe quality of the gradient
...stopsColorStop[]The color stops in the gradient

Overrides

Texture.constructor

Defined in

src/texture/gradient.ts:52

Properties

color

โ€ข color: Color

Inherited from

Texture.color

Defined in

src/texture/texture.ts:13


direction

โ€ข direction: GradientDirection = GradientDirection.LEFT_TO_RIGHT

Defined in

src/texture/gradient.ts:37


image

โ€ข image: HTMLImageElement

Inherited from

Texture.image

Defined in

src/texture/texture.ts:15


imagePath

โ€ข imagePath: string

Inherited from

Texture.imagePath

Defined in

src/texture/texture.ts:14


isOld

โ€ข isOld: boolean = false

Inherited from

Texture.isOld

Defined in

src/texture/texture.ts:16


resolution

โ€ข resolution: number = 50

Defined in

src/texture/gradient.ts:35


stops

โ€ข stops: ColorStop[]

Defined in

src/texture/gradient.ts:34


type

โ€ข type: GradientType = GradientType.LINEAR

Defined in

src/texture/gradient.ts:36


canvas

โ–ช Static Private canvas: HTMLCanvasElement

Defined in

src/texture/gradient.ts:39


ctx

โ–ช Static Private ctx: CanvasRenderingContext2D

Defined in

src/texture/gradient.ts:40

Methods

createGradient

โ–ธ createGradient(): Object

Creates the canvas gradient fill for this GradientTexture.

Returns

Object

The created gradient and dimensions of the gradient

NameType
gradientCanvasGradient
heightnumber
widthnumber

Defined in

src/texture/gradient.ts:88


getTextureUnit

โ–ธ getTextureUnit(): number

Gets the texture unit the texture is stored in on the GPU, only applies to texture's which use an image.

Returns

number

The texture unit the texture is stored in on the GPU, -1 if it is not currently loaded.

Inherited from

Texture.getTextureUnit

Defined in

src/texture/texture.ts:67


loadImage

โ–ธ loadImage(imagePath): Promise<void>

Loads an image from a path and stores it in the Texture.

Parameters

NameTypeDescription
imagePathstringA path to an image

Returns

Promise<void>

A promise that resolves once the image has loaded or rejects if there is an error while loading the image.

Inherited from

Texture.loadImage

Defined in

src/texture/texture.ts:35


refresh

โ–ธ refresh(): Promise<void>

Regenerates the gradient image.

Returns

Promise<void>

A promise which is resolved when the gradient has been loaded into the texture's image.

Defined in

src/texture/gradient.ts:69


setTextureUnit

โ–ธ setTextureUnit(unit): void

Set the texture unit to be read from when rendering the texture.

Should only be used if you know what you are doing.

Parameters

NameTypeDescription
unitnumberThe texture unit the texture is stored in on the GPU

Returns

void

Inherited from

Texture.setTextureUnit

Defined in

src/texture/texture.ts:58