RenderTexture
Offscreen canvases and subtree capture.
ts
import { RenderTexture, RenderTextureDrawOpts, ToTexture, FXAAConfig } from "willow";RenderTexture
ts
class RenderTexturePersistent offscreen canvas. Owns a GPU render target, not pooled, not recycled between frames, and provides immediate drawing methods. Draw a Texture or a TextureRegion onto it, then display the result via createSpriteNode(), which returns a Sprite whose pixels are this canvas's contents.
RenderTexture: constructors
ts
new RenderTexture(width: int, height: int)RenderTexture: properties
| Member | Description |
|---|---|
readonly width: int | Canvas width in pixels, as constructed or last resize()d. |
readonly height: int | Canvas height in pixels, as constructed or last resize()d. |
RenderTexture: methods
| Member | Description |
|---|---|
drawImage(texture: Texture, x: float, y: float): void | Draws all of texture onto this canvas at (x, y), normal blend, no tint. |
drawImageTransformed(texture: Texture, opts: RenderTextureDrawOpts): void | Draws all of texture onto this canvas with the full transform/tint/blend in opts. |
drawSprite(region: TextureRegion, x: float, y: float): void | Draws region onto this canvas at (x, y), normal blend, no tint. |
drawSpriteTransformed(region: TextureRegion, opts: RenderTextureDrawOpts): void | Draws region onto this canvas with the full transform/tint/blend in opts. |
clear(): void | Clears the canvas to fully transparent. |
fill(color: Color): void | Fills the entire canvas with color. |
createSpriteNode(name: string): Sprite | Creates a new Sprite node whose pixels are this canvas's current contents. The sprite is a live view, later draws onto this RenderTexture show up on every sprite created from it, since both reference the same GPU render target. |
resize(width: int, height: int): void | Deallocates the old canvas and creates a new one at the given size. Existing sprite nodes follow the new render target with updated dimensions. |
dispose(): void | Releases the GPU render target. Idempotent and silent, like every other dispose(). Existing sprite nodes created from this canvas are cleanly detached (rendered blank). |
RenderTextureDrawOpts
ts
class RenderTextureDrawOptsTransform/tint options for RenderTexture.drawImageTransformed / drawSpriteTransformed. color is the built-in Color, like every other colour field in this file; alpha is an additional multiplier on top of it, matching the native struct.
RenderTextureDrawOpts: constructors
ts
new RenderTextureDrawOpts()RenderTextureDrawOpts: properties
| Member | Description |
|---|---|
x: float | Draw position X in canvas pixels. Defaults to 0. |
y: float | Draw position Y in canvas pixels. Defaults to 0. |
scaleX: float | Horizontal scale factor. Defaults to 1.0. |
scaleY: float | Vertical scale factor. Defaults to 1.0. |
rotation: float | Rotation in radians. Defaults to 0. |
pivotX: float | Rotation/scale pivot X in source pixel space. Defaults to 0. |
pivotY: float | Rotation/scale pivot Y in source pixel space. Defaults to 0. |
color: Color | Tint colour. Defaults to Color.WHITE. |
alpha: float | Extra alpha multiplier on top of color's own alpha byte. Defaults to 1.0. |
blend: string | Compositor blend mode. Same string set as Node.blendMode: one of "normal" | "add" | "multiply" | "screen" | "erase" | "mask" | "below" | "none". Defaults to "normal". |
ToTexture
ts
function ToTexture(node: Node, width?: int, height?: int): RenderTextureRenders node and its descendants once into a new RenderTexture. The subtree is drawn in its own local space with the bounds origin at the canvas's top-left, so the result is the subtree cut out of the scene: show it with createSpriteNode(). Draws through Scene.main's pipeline, so it raises InvalidStateError when no Willow scene is published. A one-shot capture, not part of the frame: call it between frames (from onUpdate, not from custom paint). The caller owns the canvas and disposes it.
node: The subtree root.width: Canvas width in pixels; defaults to the subtree's bounds width.height: Canvas height in pixels; defaults to the subtree's bounds height.- Returns: A new
RenderTextureholding the subtree.
FXAAConfig
ts
class FXAAConfigSettings for an FXAA (fast approximate antialiasing) pass. Only the settings value exists today: willow has no FXAA render pass yet, so creating one changes nothing on screen.
FXAAConfig: constructors
ts
new FXAAConfig(subpixQuality?: float, edgeThreshold?: float, edgeThresholdMin?: float)FXAAConfig: properties
| Member | Description |
|---|---|
subpixQuality: float | Sub-pixel aliasing removal, 0.0 (off).. 1.0 (max). Default 0.75. |
edgeThreshold: float | Minimum local contrast required to trigger AA. Lower catches more edges but blurs more. Default 0.166. |
edgeThresholdMin: float | Skips AA on pixels below this darkness threshold, to avoid noise in shadows. Default 0.0312. |
FXAAConfig: static methods
| Member | Description |
|---|---|
static default(): FXAAConfig | FXAA 3.11 quality-15 defaults. Equivalent to new FXAAConfig(). |