pixi-reels
Reference
Cells

Symbols and pooling

The ReelSymbol lifecycle, and how the registry, factory and pool supply symbols to a reel.

A spinning reel is hungry for symbols. Every time the strip scrolls one cell past the edge, the symbol that left comes back at the other end wearing a new identity, and over a five-second spin that happens hundreds of times across five reels. If each of those moments created a new sprite and dropped the old one, the garbage collector would eventually pause the game mid-spin, and the player would see the reels stutter. A Hold & Win board makes it worse: hundreds of cells, each with its own art and maybe its own animation runtime.

So pixi-reels treats a symbol as a reusable actor rather than a disposable picture. A ReelSymbol is the object that draws one cell. Instances are borrowed from a pool, given an identity (the symbol id, like 'cherry'), shown, taken back, and lent out again. The symbol itself knows nothing about its weight, its size in cells or its draw order; that metadata lives in a separate record, SymbolData, which you set on the builder. This page follows one instance around that loop, then the three objects that run it, then the concrete symbol classes the library ships.

The lifecycle

The base class is abstract, lives in packages/pixi-reels/src/symbols/ReelSymbol.ts, and implements Disposable. Everything it shows is a child of one public container, its view. Figure 1 is the loop one instance travels. Notice that the pool is keyed by symbol id: a recycled cherry only ever comes back as a cherry. Notice too that there is one way in (the registry creates it) and one way out (destroy(), when the pool is full or the set is torn down); everything else is a trip around the ring.

createregistry.create(id)activate(id)view reset to defaultsthen onActivate(id)on the reelresize(w, h), reel hooksplayWin() / playDestroy()pooledsymbolId is ''LIFO stack per iddeactivate()stopAnimation(); onDeactivate()id = '', view hidden + resetdestroy()pool full, or teardowninstalled on the stripSymbolFactory.release()pool.release(id)hit: pop + reset()past maxPerKey
One instance, one identity, many trips around the ring. The registry creates and activates in one go; the pool is keyed by symbol id, so a recycled 'cherry' only ever comes back as 'cherry'; destroy() is the only way out.
Template methodsbase class; they call your hooks
Reel-driven hooksall no-ops by default, all idempotent
Pooledidle, invisible, id cleared
Allocationdark boxes construct or dispose

The two primary boxes are template methods: the base class owns them, and they do the housekeeping before and after calling the hook you write. Activation stores the id, makes the view visible, and resets every property a previous life might have changed (alpha, scale, rotation, filters, tint and draw order) before calling your onActivate(). Deactivation does the mirror image: it stops any animation, calls your onDeactivate(), clears the id and the landing promise, hides the view and resets the same properties again. The tint is cleared on both sides, in the source's words, "so neither half has to trust the other".

Two shortcuts are worth knowing. The pool's reset hook is deactivate(), so a recycled symbol is actually deactivated twice, once when it is released and again on the way out of the pool; that is harmless precisely because the hook is idempotent. And when a symbol wraps around and the next identity is the same id it already has, the reel skips the whole ring: it calls stopAnimation() and nothing else, with no trip through the pool. The table has the exact sequence of each template method.

Template methodWhat it does, in order
activate(symbolId)stores the id; sets view.visible = true, alpha = 1, scale = (1, 1), rotation = 0, filters = null, tint = 0xffffff, zIndex = 0; then calls onActivate(symbolId)
deactivate()calls stopAnimation(), then onDeactivate(); clears the id to '' and landing to null; hides the view and resets the same properties
reset()the pool hook; calls deactivate()
destroy()returns early if already destroyed; runs stopAnimation() and onDeactivate() if the view is still alive (a game can destroy a container that holds it); then onDestroy() and view.destroy({ children: true })
same-id wrapstopAnimation() only; no deactivate, no activate, no pool

What a subclass implements

Five members are required, and the base class provides a no-op or a sensible default for everything else. The optional hooks fall into two groups: presentation one-shots the game calls (landing, destroy, out and in), and reel-driven hooks the engine calls as the reel changes state, so a symbol can relax or sharpen its art as it spins, teases and lands.

MemberRequiredDefault and contract
onActivate(symbolId)yesswap the texture, restart idle, leave any ended pose
onDeactivate()yespause animations, clear listeners, leave a clean state
playWin(): Promiseyesresolves when the one-shot finishes; settle it on recycle or await hangs
stopAnimation()yesreturn to idle immediately
resize(width, height)yesstore the size and reposition children. Runs on every symbol swap. Forgetting it is "the single most common why do my symbols scatter bug"
onDestroy()nono-op; release subclass resources here
playLanding()noresolves immediately; never called by the engine, for callers that land cells one at a time (Hold & Win lockAnimation)
playDestroy({ delay, signal })nothe cascade poof: pivot to the bounds centre (position compensated by (c - pivot) * scale), pop to 1.1 over 0.06 s with back.out(2.5), then scale 0 and alpha 0 over 0.14 s with power3.in starting 0.04 s in; about 200 ms. Abort skips to the end. Pivot, position and scale 1 are restored; alpha stays 0
playOut(opts) / playIn(opts)nothe mystery-reveal seam. Out: scale 0.72 and alpha 0 over 0.18 s, power2.in. In: owns its start pose (visible, alpha 0, scale 0.72), then scale 1 over 0.2 s with back.out(1.7) and alpha 1 over 0.16 s with power2.out. Scale always returns to 1
cellInsetnonull, meaning the art fills the whole cell; sprite subclasses derive it from the texture trim
applyCellQuad(quad | null)nocurved reels: an affine contain-fit about the quad centre, paid for through the pivot. Must never move view.position
onReelSpinStart(joinedMidSpin?)nofires on every strip symbol, buffers included, when the reel enters spin; again with true for each symbol installed mid-spin
onReelSpinEnd()nofires just before the bounce
onReelAnticipationStart()nofires when the tease begins; relax spin presentation so the strip is readable
onReelLanded(ctx)nofires before the reel's landing event; ctx = { reelIndex, reelCount, cell, visibleCells, symbolId }

Three more things the base class gives you. The first is this.gsap, a protected getter the factory binds when the symbol is created. Always animate through it rather than through an imported gsap, because a symlinked workspace can load two copies of the library. The second is mainAxis ('x' or 'y'), bound the same way; only motion-blur effects read it. The third is landing, the promise started by the latest onReelLanded(). A subclass sets it through trackLanding(run), the reel clears it when it leaves rest, and a board can await symbol.landing to know when a cell has finished arriving.

Registry, factory, pool

Three small objects run the loop, and it helps to separate their jobs. The registry knows which class draws which id. The pool remembers idle instances. The factory sits between the reel and the other two: a reel asks it for a symbol by id, and it either pops one from the pool or asks the registry to make a fresh one. Figure 2 follows one request left to right and the return trip underneath. Notice that the registry is only consulted on a miss, and that the dashed arrow is the only place a new object is allocated.

Reelresize, place, zIndexemits symbol:createdSymbolFactoryacquire(id) / release()binds gsap and the axisObjectPoolMap<id, T[]>, LIFOhit: pop + reset()SymbolRegistryregister(id, Class)create: new + activateacquire(id)pool.acquire(id)miss: create(id)release(symbol)
acquire() flows left to right and release() comes back underneath. The registry creates and activates; the factory binds gsap and the axis; the pool only remembers idle instances.

You meet the registry once, inside builder.symbols(registry => ...), where you register each id with the class that draws it and that class's options. One entry per id, and a duplicate throws; if one class draws ten ids, that is ten calls. When asked to create an id, the registry constructs the class and activates the instance immediately, so a fresh symbol arrives already dressed; an unknown id throws with the list of registered ones. The registry has no idea of size, weight or draw order, which belong to SymbolData.

The factory has been internal since PR #140; you never construct it, the builder does. When the pool misses, the factory asks the registry for a new instance and binds two things to it for life: the gsap instance and the main axis. They are bound at creation rather than on every acquire because a pooled symbol never moves between reel sets. On acquire, the factory only re-activates a symbol whose current id differs from the one requested, since a fresh instance was already activated by the registry. On release it deactivates the symbol, detaches it from any render layer it was promoted to, removes it from its parent, and hands it to the pool, which keeps it or, if that id's stack is already full, destroys it.

The pool, ObjectPool<T> in pool/ObjectPool.ts, is a public export and is deliberately simple: one last-in-first-out stack per key. Acquiring pops and resets, or calls the factory on a miss. Releasing pushes, unless the item is already in the pool (a guard against the same object being handed out twice) or the stack is at its cap, in which case the item is destroyed. Releasing after the pool is destroyed is a no-op, while acquiring after that throws, because it means a ticker or promise is outliving teardown. There is no pre-allocation and no cap on live objects, only on how many idle ones are kept; setMaxPerKey trims any excess at once.

The names, for reference. The factory is constructed as SymbolFactory(registry, maxPoolPerKey = 20, gsap = DEFAULT_GSAP, mainAxis = 'y'); its verbs are acquire(id) and release(symbol), and release runs deactivate(), view.parentRenderLayer?.detach(view), view.removeFromParent() and pool.release(id, symbol) in that order. The pool's verbs are acquire(key), release(key, item), setMaxPerKey and destroy(). The builder sizes the pool like this:

// pool capacity, set by the builder
poolCapacity = builder.poolCapacity(n) ?? max(20, sum over reels of (visible + bufferStart + bufferEnd))
// a MultiWays reel counts at maxCells; the worst case for one id is the whole strip showing it
// DEFAULTS.maxPoolPerKey = 20; ReelSet.addReels() / removeReels() call setCapacityPerKey

symbolData and draw order

Everything the engine knows about a symbol that is not how to draw it lives in SymbolData (config/types.ts): its weight in random draws, its draw order within the reel, whether it may escape the mask, and its size in cells. You set these on the builder, through weights() and symbolData(), and the builder fills in a weight of 10 and a draw order of 1 for every id you did not mention; the size defaults to one cell. A symbol marked unmask: true is lifted into the viewport's unmasked layer while its reel is at rest, so its art can overhang the cell.

view.zIndex = symbolData.zIndex * 100 + stackingIndex
// stackingIndex = strip array index (cellStacking 'ascending') or length - 1 - index ('descending')
// Z_INDEX_BUDGET.symbolLayer = 100; pin overlays sit at 10000; destroy and swap bumps use 1000

That formula is how the engine turns the metadata into a PixiJS zIndex: your draw order, times a hundred, plus the symbol's position in the strip, so cells of the same kind layer in strip order. It only sorts within one reel's container; to draw across reels you need unmask: true. If you need a different rule, pass a resolver to builder.symbolZIndex(); it replaces the formula outright. The resolver receives { symbolId, symbolData, reelIndex, reelCount, arrayIndex, visibleCell | null, visibleCells, atRest, defaultZIndex } and must be pure and cheap, because the engine calls it after every wrap, snap, swap and rest transition. One drift to know: the ReelSet doc table says the default draw order is ?? 0, but the builder writes ?? 1, so built symbols start at 100 + index. The code is the source of truth here.

Big symbols

Some symbols are bigger than one cell: a 2 x 2 bonus tile, a wild that fills a whole reel. The engine handles these without a special symbol class. The server names the symbol in one cell only, the anchor, and the other cells the block covers become invisible placeholders. Figure 3 shows a 2 x 2 block anchored at reel 1, cell 0. Notice that the anchor's view has been resized to cover all four cells, gap included, and that the three other cells are stubs rather than cherries or blanks.

0,00,10,2stubOCCUPIED1,2stubOCCUPIEDstubOCCUPIED2,23,03,13,24,04,14,2anchor'bonus'size.reels = 2size.cells = 2
A 2 x 2 block anchored at reel 1, cell 0. The server sends 'bonus' at the anchor only; the other three cells become invisible OCCUPIED stubs, and the anchor's view is resized to cover the whole block, gap included.

You declare a block on the builder, not in the registry: symbolData({ bonus: { size: { reels: 2, cells: 2 }, zIndex: 5 } }). Its weight must be 0, because random fill never places blocks; only the server does, and only at anchor cells. size.reels always runs along the cross axis and size.cells along the main axis, whatever the orientation. The anchor's view is resized to the block size, which here is two cells plus one gap on each axis, and getVisibleGrid() reports 'bonus' in all four cells, so code that reads the grid sees the block, not the stubs.

The function that lays blocks out is coordinateBigSymbols in spin/bigSymbolBlocks.ts. It is pure, it runs in the spin controller before any reel builds its frame, it throws with a named message when a block does not fit, and it sits on every path that puts a grid on the reels: landing, the initial frame, adding or removing reels and rows, and pinning or moving pins. A block may be partly off screen: an anchor can sit in the start buffer with its tail visible, and stubs can spill into the end buffer. The stub itself, OccupiedStub, is an internal symbol in core/Reel.ts that sets itself invisible on activate; each reel allocates its own stubs lazily and reuses them rather than going through the factory.

Three limits: big symbols cannot be combined with multiways(), a non-anchor cell cannot be pinned, and a block spanning reels whose cell sizes differ logs a one-time warning. The recipes use zIndex: 5 for anchors so a block draws above its neighbours. See the big symbols guide.

The concrete classes

The library ships a symbol class for each common kind of art, plus two for debugging and two internal helpers. The table has each one's options with their defaults and what it does with the hooks above; most games start with SpriteSymbol and reach for a Spine class when the art is rigged.

ClassOptions and defaultsBehaviour
SpriteSymboltextures: Record<id, Texture>; anchor, in code { 0, 0 }onActivate swaps the texture and syncs the perspective mesh. playWin: scale pulse to 1.15 over 0.15 s, yoyo, one repeat, power2.inOut; _killWinTween always settles a pending await. resize sets sprite width and height only. On curved reels it draws through a PerspectiveMesh and falls back to the affine fit for atlas sub-frames; cellInset comes from the texture trim.
AnimatedSpriteSymbolframes: Record<id, Texture[]>; animationSpeed 1; anchor, in code { 0, 0 }; loop = falseonActivate sets textures and gotoAndStop(0). playWin is gotoAndPlay(0), returning to frame 0 on complete. onFrameChange pushes every frame to the perspective mesh so a curved win does not freeze. resize sets the size and positions the sprite at size * anchor.
SpineSymbol (core, optional peer)skeletonDataMap; idleAnimation 'idle'; winAnimation 'win'; defaultSkin 'default'; strict falseLoaded by a dynamic import; constructing before whenSpineReady() resolves throws. One Spine per instance, rebuilt on a new id, idle looped on track 0. playWin plays win once; listener on the TrackEntry. onDeactivate settles the win and clearTracks() only. resize is a non-uniform stretch from getBounds() with no positioning; from reading the code, a second resize at the same size can undo the fit because getBounds() includes the current scale.
SpineReelSymbol (pixi-reels/spine)spineMap { skeleton, atlas, skin? }; idle 'idle', win 'win', landing 'landing', out 'disintegration', blur 'blur'; animations overrides per id; scale 1; autoPlayBlur false; autoPlayLanding false | fnOne Spine per id, parked (visible false, autoUpdate false) when not on screen, update(0) on activate so a snapshot sees the pose. playOneShot(name, { track = 0, then }) returns a promise settled on complete, interrupt or end; then defaults to idle on track 0 and clear elsewhere, hold keeps an overlay. playWin, playLanding (via trackLanding) and playOut (then: hold) are built on it. playDestroy plays the out animation or falls back to the base poof. playBlur is idempotent. onDeactivate settles one-shots, clearTracks, setToSetupPose, parks. resize re-centres only: no fit-scaling, author at cell size or use scale.
CardSymbol (debug)color; label; textColor 0xffffff; font Roboto Condensed 32 boldidentity fixed at construction, so onActivate and onDeactivate are no-ops. playWin: glyph to 1.4 over 0.18 s with back.out(2), a rotation wobble of 0.12 rad, back to 1 at 0.32 s, fill flashes 0xffe168 at 0.06 s and restores at 0.42 s. resize draws a (0, 0, w, h) rect with an inset 2 px stroke at alpha 0.25 and sets fontSize = max(7, floor(min(0.38 * h, 0.7 * w / (len * 0.45)))). Exports CARD_DECK (7, 8, 9, 10, J, Q, K, A) and WILD_CARD.
PhaseCardSymbol (debug)label; textColor; colors; landedMs 350extends CardSymbol. setPhase(phase) repaints; 'landed' reverts to 'rest' after landedMs. static watch(reels) subscribes to phase:enter, landed and symbol:created and returns an unsubscribe.
EmptySymbolnoneevery hook is a no-op; renders nothing. Hold & Win blanks, cascade holes, placeholders. HoldAndWinBuilder registers it under emptyId.
OccupiedStub (internal)noneinvisible filler for non-anchor big-symbol cells; allocated by the Reel, not the factory.
StaticSpinSymbol + SpinTextureCachecreateInner; cache; spinTexture 'blurred'; blurRampMs 120; blur (axis = the set's mainAxis)Wraps an inner symbol. On spin start it captures a crisp snapshot while the inner is still live, crossfades to a pre-baked blur over 120 ms, then deactivates the inner so it costs nothing while spinning. Anticipation fades the blur out. On spin end it reactivates the inner on the final id. The cache is one per reel set, keyed by id plus size (rounded to 0.001 px) plus axis; blur strength defaults to 0.2 of the cell, quality 4, padding ceil(strength), baked once with no per-frame filter. prewarmSpinTextures() fills it at load time.

The Spine animation vocabulary

A Spine symbol is driven by animation names, and the library agrees on a small vocabulary so a rigged symbol works out of the box: one looping idle, a few one-shots for the moments a slot cares about, and a looping blur for fast spins. Every name can be overridden per id. The table lists each role, its default name, and what triggers it.

RoleDefault nameLoopsHow it plays
Restingidleyesautomatically on activate
Reel-stop one-shotlandingnoplayLanding() or autoPlayLanding
WinwinnoplayWin()
Cascade pop / exitdisintegrationnoplayOut() / playDestroy()
Fast spinbluryesplayBlur() or autoPlayBlur
Neighbour cuereactions/react_{u,d,l,r,ul,ur,dl,dr}noraw spine.state, or playOneShot(name, { track: 1 })

A missing animation is a silent no-op. The library never throws because a skeleton lacks a name; the one opt-in exception is the core SpineSymbol's strict mode (ADR 011). There is one rule about listeners that comes from a real bug. Attach completion listeners to the TrackEntry, never to the whole animation state, and null the listener once it has fired, because Spine pools track entries. Never clear the state's listeners during the symbol's life either, since the game may have added some of its own; clearListeners() runs only in onDestroy. Removing a state listener in the middle of a dispatch once made the other listeners miss their events. The Spine runtime stays out of the core bundle: import SpineReelSymbol only from pixi-reels/spine.

For completeness, PHASE_CARD_COLORS is the palette PhaseCardSymbol paints with: rest 0x4b5563, start 0x38bdf8, spin 0x2563eb, anticipation 0xf59e0b, stop 0x8b5cf6, landed 0x22c55e, adjust 0xec4899, cascade:fall 0x0ea5e9, cascade:place 0x14b8a6, cascade:dropIn 0x06b6d4, other 0x9ca3af.

Random-draw pools and scopes

The word "pool" is used for a second, unrelated thing: the set of ids a reel may draw from at random while it spins, and how likely each one is. A SymbolPool is { weights?, exclude? }, and a weight of 0 removes an id as fully as excluding it. A scope says where the pool applies: optionally one reel, and one of four slot kinds. 'spinning' is every random draw and the default. 'buffer' is both off-window sides. 'bufferStart' is the side with the smaller coordinate (above on a vertical set, left on a horizontal one) and 'bufferEnd' the other. Pools layer, widest first:

base weights -> global spinning -> per-reel spinning -> global buffer -> per-reel buffer -> global side -> per-reel side
// weights override per id; exclusions accumulate: a narrower layer can only ban more, never re-admit
// changes apply to the next draw; symbols already on the strip stay until they wrap out

At build time pools come from builder.randomSymbols(pool, scope); at runtime reelSet.randomSymbols exposes set(pool | null, scope?), clear() and weights(scope?). The provider validates every id, compiles every reachable table, and rolls the change back with the error No symbol left to draw for ... cells on reel N if a scope would end up empty. Each draw is a binary search over a cached cumulative-weight table using the injected rng (builder.rng(fn), default Math.random), so a weighted draw stays cheap. See the frame pipeline.

Conventions and gotchas

Most symbol bugs come from one of five habits, and most of those follow from pooling. First, the view's origin is the cell's top-left corner, and the reel owns it: the reel places view there and reads view.position back to find the slot, so a symbol must never move its own position. Curve fits and destroy tweens use the pivot instead. Second, implement resize() properly: it runs on every symbol swap, and it must store the size and reposition children without assuming an anchor centres anything.

Third, settle every promise when a symbol is recycled. Each built-in does this in its own way (_killWinTween in SpriteSymbol, stopAnimation in AnimatedSpriteSymbol, _settleWin and _settleOneShots in the Spine classes, _endWin in CardSymbol), and if yours does not, an await playWin() somewhere in the game hangs forever. Fourth, remember the same-id fast path: it skips deactivate and activate entirely, so the reel calls stopAnimation() itself and resets alpha, scale, rotation, filters and tint, and no symbol:created event fires. Fifth, for Spine, parked skeletons do not tick. Only the on-screen Spine has autoUpdate, which is what makes a Hold & Win board with hundreds of cells affordable, but it means you must reset to the setup pose on deactivate or a disintegrated symbol comes back invisible.

All of this runs without a renderer. HeadlessSymbol from pixi-reels/testing is a ReelSymbol that draws nothing, and the whole lifecycle above, pool included, runs in Node.

Where this lives

Under packages/pixi-reels/src/: symbols/ReelSymbol.ts and the Sprite, AnimatedSprite, Spine, Card, PhaseCard and Empty files beside it, with SymbolRegistry.ts, SymbolFactory.ts and PerspectiveCell.ts; pool/ObjectPool.ts; spine/SpineReelSymbol.ts; snapshot/SpinTextureCache.ts and StaticSpinSymbol.ts; frame/SymbolPool.ts and RandomSymbolProvider.ts; spin/bigSymbolBlocks.ts; and the OccupiedStub in core/Reel.ts. Guides: symbols, win animations, big symbols. Recipes: symbols, big symbols.