Skip to content

Documentation / spryte / SpritesEach

Interface: SpritesEach ​

Defined in: copies.ts:16

Optional per-copy values for draw.sprites. Each array has one entry per copy.

Interleaved data: set stride and positions becomes one record of stride floats per copy (a Float32Array, which may view a SharedArrayBuffer). The fields then take offsets into the record instead of arrays, and the record goes to the GPU as is, with no per-copy work:

ts
// [x, y, scale, colour bits] per copy; write colours through a Uint32Array view of the same buffer.
draw.sprites(dot, data, n, {}, { stride: 4, scale: 2, color: 3 });

Properties ​

color? ​

optional color?: number | Uint32Array<ArrayBufferLike>

Defined in: copies.ts:29

0xRRGGBBAA per copy, multiplied with tint and alpha. A Uint32Array, uploaded as is. With stride, an offset into each record whose bits are read as a Uint32 (write it through a Uint32Array on the same buffer).


frame? ​

optional frame?: number | ArrayLike<number>

Defined in: copies.ts:36

Frame per copy: an index into the Frame[] passed as draw.sprites' first argument (an index past the end throws). Frames on one image stay one draw call; frames across images draw one quad per copy (warned once in development). With stride, an offset into each record.


position? ​

optional position?: number

Defined in: copies.ts:20

With stride: offset of x in each record (y follows). Default 0.


rotation? ​

optional rotation?: number | ArrayLike<number>

Defined in: copies.ts:24

Radians per copy, added to rotation. With stride, an offset into each record.


scale? ​

optional scale?: number | ArrayLike<number>

Defined in: copies.ts:22

Uniform scale per copy, multiplied with scaleX/scaleY. With stride, an offset into each record.


stride? ​

optional stride?: number

Defined in: copies.ts:18

Floats per copy in positions, for interleaved data. Without it, positions is x, y pairs.


user? ​

optional user?: number | ArrayLike<number>

Defined in: copies.ts:59

One float per copy for a custom shader to read as user() (a copy's place in a row, a particle's age, a tile variant). Since spryte 0.13. With stride, an offset into each record.

ts
const fade = draw.createShader(`
  uniform float time;
  vec4 effect(vec4 color, highp vec2 uv) {
    float t = clamp((time - user() * 0.05) * 4.0, 0.0, 1.0); // each copy starts 50 ms after the last
    return source(uv) * color * t;
  }
`);
fade.set("time", seconds);
draw.withShader(fade, () => draw.sprites(tile, positions, n, {}, { user: place })); // place[i] = i

Limits: user() is 0 for everything that isn't a draw.sprites copy or a draw.sprite with its own user option (since 0.16; before that, sprite() always read 0), such as text() and shapes. The default program ignores the value, and so does the Canvas 2D fallback, which ignores shaders altogether. The count is clamped to the shortest array, as for the other fields. A float holds whole numbers exactly up to 16,777,216.


user2? ​

optional user2?: number | ArrayLike<number>

Defined in: copies.ts:64

A second float per copy, read as user2(), for a shader that needs two (a glyph's place and its line). Same rules as user. Experimental, added 2026-11-09.