Texture2D
Wrapper around a GPUTexture with convenient factory methods.
Factory methods
Section titled “Factory methods”static fromUrl(surface, url)
Section titled “static fromUrl(surface, url)”Load a texture from a URL (async).
const tex = await Texture2D.fromUrl(surface, '/sprites/hero.png')static fromImageSource(surface, source)
Section titled “static fromImageSource(surface, source)”From an HTMLImageElement, ImageBitmap, HTMLCanvasElement, or OffscreenCanvas.
const tex = Texture2D.fromImageSource(surface, myImageBitmap)static fromColor(surface, r, g, b, a?)
Section titled “static fromColor(surface, r, g, b, a?)”Create a 1x1 solid-color texture.
const white = Texture2D.fromColor(surface, 1, 1, 1)Members
Section titled “Members”| Member | Type | Description |
|---|---|---|
width | number | Texture width in pixels |
height | number | Texture height in pixels |
view | GPUTextureView | The GPU texture view |
Methods
Section titled “Methods”destroy()
Section titled “destroy()”Release the GPU texture.
tex.destroy()