The 2D layer · interface

SpritePass

Explained in Sprites and tilemaps.

interface SpritePass extends PassDefinition
import type { SpritePass } from '@driftengine/ui2d';

Properties

NameTypeDescription
batchreadonlySpriteBatchThe quads for this frame. Reset it, fill it with drawSprite, then call drawPass.
More

Held by the pass rather than handed in per frame, because its size is the pass's GPU buffer and the two must agree.

whitereadonlynumberA slot holding one opaque white texel, filled by the pass and not settable.
More

White is the identity of the multiply the shader does, so a quad on this slot draws exactly its tint — which is what a solid rectangle is, and what fillPanel in core does with a whole program of its own. A caller drawing a filled box needs no sheet for it.

A background on this slot and an image from a sheet are two runs, because a slot change is a run and the order may not be regrouped. A caller with many filled boxes and many images interleaved should pack a white texel into its own sheet and tint a frame of that instead: then the whole tree is one run. This slot is the convenience, and the sheet is the fast path.

Methods

reset

reset(): void

Clear the batch. Call once at the top of a frame.

setTransform

setTransform(affine: Affine2D): void

Where the batch's coordinates are, from screenToNdc or worldToNdc.

ParameterTypeDescription
affineAffine2D
More

Copied, so the caller may reuse its array; and read at draw time, so this can be called before the pass has a device.

setTexture

setTexture(slot: number, source: SpriteImage, options?: SpriteTextureOptions): void

Fill a texture slot. Safe before the pass is registered; applied when it gets a device.

ParameterTypeDescription
slotnumber
sourceSpriteImage
options?SpriteTextureOptions