Skip to content

RenderTexture ​

Offscreen canvases and subtree capture.

ts
import { RenderTexture, RenderTextureDrawOpts, ToTexture, FXAAConfig } from "willow";

RenderTexture ​

ts
class RenderTexture

Persistent 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 ​

MemberDescription
readonly width: intCanvas width in pixels, as constructed or last resize()d.
readonly height: intCanvas height in pixels, as constructed or last resize()d.

RenderTexture: methods ​

MemberDescription
drawImage(texture: Texture, x: float, y: float): voidDraws all of texture onto this canvas at (x, y), normal blend, no tint.
drawImageTransformed(texture: Texture, opts: RenderTextureDrawOpts): voidDraws all of texture onto this canvas with the full transform/tint/blend in opts.
drawSprite(region: TextureRegion, x: float, y: float): voidDraws region onto this canvas at (x, y), normal blend, no tint.
drawSpriteTransformed(region: TextureRegion, opts: RenderTextureDrawOpts): voidDraws region onto this canvas with the full transform/tint/blend in opts.
clear(): voidClears the canvas to fully transparent.
fill(color: Color): voidFills the entire canvas with color.
createSpriteNode(name: string): SpriteCreates 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): voidDeallocates the old canvas and creates a new one at the given size. Existing sprite nodes follow the new render target with updated dimensions.
dispose(): voidReleases 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 RenderTextureDrawOpts

Transform/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 ​

MemberDescription
x: floatDraw position X in canvas pixels. Defaults to 0.
y: floatDraw position Y in canvas pixels. Defaults to 0.
scaleX: floatHorizontal scale factor. Defaults to 1.0.
scaleY: floatVertical scale factor. Defaults to 1.0.
rotation: floatRotation in radians. Defaults to 0.
pivotX: floatRotation/scale pivot X in source pixel space. Defaults to 0.
pivotY: floatRotation/scale pivot Y in source pixel space. Defaults to 0.
color: ColorTint colour. Defaults to Color.WHITE.
alpha: floatExtra alpha multiplier on top of color's own alpha byte. Defaults to 1.0.
blend: stringCompositor 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): RenderTexture

Renders 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 RenderTexture holding the subtree.

FXAAConfig ​

ts
class FXAAConfig

Settings 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 ​

MemberDescription
subpixQuality: floatSub-pixel aliasing removal, 0.0 (off).. 1.0 (max). Default 0.75.
edgeThreshold: floatMinimum local contrast required to trigger AA. Lower catches more edges but blurs more. Default 0.166.
edgeThresholdMin: floatSkips AA on pixels below this darkness threshold, to avoid noise in shadows. Default 0.0312.

FXAAConfig: static methods ​

MemberDescription
static default(): FXAAConfigFXAA 3.11 quality-15 defaults. Equivalent to new FXAAConfig().