Texture and TextureRegion
Images on the GPU and rectangles inside them.
ts
import { Texture, TextureRegion } from "willow";Texture
ts
class TextureTexture handle backed by a GPU resource. Textures can be loaded from a path or encoded bytes, or created from RGBA pixels. Direct new Texture(...) raises a TypeError.
Texture: properties
| Member | Description |
|---|---|
readonly height: int | Texture height in pixels. |
readonly width: int | Texture width in pixels. |
Texture: methods
| Member | Description |
|---|---|
dispose(): void | Releases the GPU resource. Idempotent and silent, like every other dispose(). |
update(rgba: Buffer | Uint8Array): void | Replaces all RGBA pixels of an updatable texture. |
Texture: static methods
| Member | Description |
|---|---|
static load(path: string, opts?: any): Texture | Loads a texture from path (resolved via the engine asset roots). Pass { cache: false } to bypass the process-wide path cache. |
static fromBuffer(buffer: Buffer): Texture | Loads a PNG or JPEG texture from encoded bytes. |
static fromPixels(width: int, height: int, rgba: Buffer | Uint8Array, updatable?: boolean): Texture | Creates a texture from width * height * 4 RGBA bytes. Requires an initialized renderer, so it is unavailable in a headless console program. Set updatable to true when the pixels will later be replaced. |
TextureRegion
ts
class TextureRegionA rectangular sub-region of a texture with its source rectangle and pre-computed UVs. Direct new TextureRegion(...) raises a TypeError.
TextureRegion: properties
| Member | Description |
|---|---|
readonly x: float | Source x within the texture, in pixels. |
readonly y: float | Source y within the texture, in pixels. |
readonly width: float | Region width in pixels. |
readonly height: float | Region height in pixels. |
TextureRegion: static methods
| Member | Description |
|---|---|
static grid(tileset: Texture, tileWidth: int, tileHeight: int, opts?: any): Array<TextureRegion> | Slices a regular grid tileset into an ordered Array<TextureRegion> (row-major, element 0 = the first cell = GID 1). opts accepts { columns?, count?, margin?, spacing? }; columns/count are derived from the texture size when omitted. |
static fromRect(texture: Texture, x: float, y: float, width: float, height: float): TextureRegion | Creates an axis-aligned pixel rectangle within texture. |