Classes
The ownership tree. Who owns what, who destroys what.
A reel set is a lot of objects. Five reels of a few symbols each means dozens of containers and sprites, plus the tweens that bounce them, the ticker callbacks that move them every frame, the pooled symbols waiting off screen, and the listeners your game attached. Slot games tear this down and build it again all the time: a bonus round opens, a free-spins board replaces the base board, the player switches games. If one ticker callback survives that teardown it will run on a reel that no longer exists and throw on the next frame; if one tween survives, it will animate a destroyed sprite. The library's own source calls dangling ticker callbacks the number one memory leak in the original engine.
The answer is strict ownership. Every object in pixi-reels has exactly one parent, the parent is responsible for destroying it, and one call at the top, reelSet.destroy(), cascades down the whole tree in a fixed order. This page is that tree: who constructs what, who owns what, and in what order it all comes apart.
Three layers
It helps to sort the classes into three layers before looking at the tree. The outer shell is what you build: the builder and the set it returns. The scene graph is what PixiJS renders: the viewport, the reel containers and the symbols inside them. The internals are the objects that exist for the duration of a spin and do the timing, the counting and the choosing; none of them draws anything. Ownership reads top to bottom through all three, and the parent always destroys its children.
Construction is split between two places, and it is worth knowing which is which. The builder constructs the viewport, the symbol factory, the frame builder, the random provider, the phase factory and the reels, and hands them all to the ReelSet through one params object. The ReelSet then constructs the three subsystems that need the set to exist first: the SpeedManager, the SpinController and the SymbolSpotlight.
The ownership tree
Figure 1 is the ReelSet after build() returns. Notice that only one box, the viewport, is a display child that PixiJS draws; the other seven are plain objects the set holds. The reels at the bottom are owned by the set as objects, but their containers live inside the viewport, which is why the next figure opens one reel on its own.
Figure 2 is one reel. Each reel carries six things: an axis object that says which way it travels, the motion that moves its strip every tick, a queue of the symbols it must land on, the symbols themselves, the PixiJS container they sit in, and a small event bus of its own. Notice that the container's draw order is its reel index, positive or negative depending on the stacking you chose, which is what decides whether the last reel draws in front or behind.
What each class does, in plain English
Every class in the two figures, one card each. If a name on another page feels opaque, this is the place to look it up.
ReelSetBuilderbuilderA fluent, chainable configurator. You call .reels(5).visibleCells(3)... and end with .build(). Every required piece of setup is forced into one place: forget .ticker(app.ticker) and build() throws before the game boots. The builder page walks build() step by step.
ReelSetscene graph rootThe thing you app.stage.addChild(reelSet). A PixiJS Container that owns every reel, the spin controller, the speed manager, the win spotlight and the symbol pool. The public verbs live here: spin(), setResult(), setAnticipation(), skipSpin(), destroy(). Its only display child is the ReelViewport.
Reelone stripOne strip of symbols, longer than the window by the buffer cells on each end. It spins along whichever axis the set uses (vertical or horizontal, forward or reverse). A Reel owns its symbols, its container, its motion, its stop queue and its own event bus. You rarely touch one directly; you drive the ReelSet and let it fan out.
ReelViewportclip and layersThe window you look through. Holds one mask Graphics for the whole masked container, plus the layers above the mask (unmasked, dim, spotlight, promoted) that presentation uses to break out of it. The viewport page has the five layers.
ReelAxisorientationThe small object that turns main-axis and cross-axis numbers into screen x and y. reelAxis(orientation, direction) gives each reel its own, so a horizontal or reversed reel runs through exactly the same motion code.
ReelMotionthe physicsMoves the strip every tick and derives each symbol position from its array index. When a symbol passes the far edge it rotates the array and tells the reel a wrap happened. That callback is where a spinning reel takes on its next identity.
StopSequencerlanding queueA queue holding the symbols a reel must land on, in order. The stop phase loads one frame into it; every wrap pops the next id. A forward reel consumes the frame end-first, a reverse reel head-first. When the queue is empty the reel stops.
SpinControllerconductorRuns each reel through start, spin, optional anticipation and stop, gates stopping on setResult(), turns presses into slams or quickens, fires the spin:* events and resolves the promise you awaited. It owns the one TickerRef in the engine and the active phase per reel. It draws nothing.
ReelPhasestateAbstract base for one stage of a reel spin. Stock phases: StartPhase, SpinPhase, AnticipationPhase, StopPhase, AdjustPhase (MultiWays) and the three cascade phases (CascadeFallPhase, CascadePlacePhase, CascadeDropInPhase). The PhaseFactory maps a phase key to a constructor.
SpinningModestrategyWhat a spin means. StandardMode runs every reel through the phase machine. CascadeMode handles tumble refills. ImmediateMode snaps straight to the result, which tests use. The builder default is new StandardMode().
SpeedManagertempoNamed bundles of timings. Ships with SpeedPresets.NORMAL and friends; switch at runtime with reelSet.setSpeed(name), which emits speed:changed. Constructed by the ReelSet from the builder speeds map.
ReelSymbolabstract cellOne visible cell. Subclass it to draw anything. Built-ins: SpriteSymbol, AnimatedSpriteSymbol, SpineSymbol, CardSymbol, EmptySymbol. Implement onActivate, onDeactivate, playWin, stopAnimation and resize for a new kind. The symbols page has the lifecycle.
SymbolRegistry / SymbolFactorypoolSymbolRegistry records which class and options render which id. SymbolFactory sits on top with an ObjectPool keyed by id, so scrolling a 5x3 set for five seconds allocates no new symbol objects once the pool is warm.
FrameBuilder + middlewarepipelineDecides which id fills each slot of a target strip. random-fill is priority 0, target-placement is priority 10, and your own middleware slots in by priority. It runs once per result, not on every wrap.
SymbolSpotlightwinsThe win primitive. show(positions) dims the losers and runs playWin() on the winners in the spotlight layer; cycle(winLines) steps through lines and emits spotlight:start and spotlight:end.
EventEmitterpub / subTyped, colon-namespaced events on two buses: reelSet.events (ReelSetEvents) and reel.events (ReelEvents). The ReelSet uses its own emitter so it never collides with the Container events PixiJS itself emits.
TickerRefsafe tickerA wrapper around PIXI.Ticker that remembers every callback it adds and removes them all on destroy(). Nobody in the engine calls ticker.add() directly.
DisposableinterfaceThe cleanup contract: destroy() plus a readonly isDestroyed. Anything that subscribes to a ticker, creates display objects or holds references implements it, and reelSet.destroy() cascades through the whole tree.
FakeTicker + HeadlessSymboltestsThe headless harness from pixi-reels/testing: a ticker you step by hand and a symbol that draws nothing. A full spin runs in Node without a renderer. See the testing page.
Teardown order
ReelSet.destroy() is the single source of truth for teardown. It guards against a second call, marks the set destroyed, and then runs the ten lines in figure 3, in that order. The order is not arbitrary. The spin controller goes before the reels so no frame callback lands on a dead reel. The symbol pool goes before the viewport so that symbols released into the pool are detached from the viewport's promoted layer before that layer dies. And the destroyed event fires one line before the listeners are dropped, so anyone waiting on it still hears it. Read the figure top to bottom and notice that each step only touches things the steps above it have not freed yet.
Two of the steps need a word of explanation. A pin is a cell that stays put across spins (a sticky wild, a held coin), and the engine draws it with an overlay that is itself a pooled symbol. That is why the pin overlays at step 4 are destroyed after the reels but before the pool: each overlay is released back into the pool, and the pool at step 5 then disposes of everything it holds. The second is step 9. Once the listeners are gone the bus is gone too, which is why the error handler in nudge() checks isDestroyed before trying to emit nudge:cancelled: an emit after this line would be shouting into an empty room.
The Disposable contract
Every class that holds a resource promises the same two things: a destroy() method, and a flag that says whether it has already run. That is the whole interface.
export interface Disposable {
destroy(): void;
readonly isDestroyed: boolean;
}Anything that subscribes to a ticker, creates display objects or holds references implements it. Every destroy() in the engine is safe to call twice: it returns early when isDestroyed is already set, which is what lets the cascade be simple rather than careful. If you add a subsystem of your own that holds resources, it must implement Disposable and be destroyed from the chain above, or it leaks. The list below is who owns what, so you can see which call frees which resource.
ReelSetowns: viewport, reels, symbol factory, frame builder, spin controller, speed manager, spotlight, pins, eventsReelowns: axis, motion, stopSequencer, symbols, container, events, occupied stubsSpinControllerowns: TickerRef, the active phase per reel, cached framesSymbolSpotlightowns: gsap timelines, the dim request, reparented winner viewsSymbolFactoryowns: ObjectPool<ReelSymbol>; pool.destroy() disposes every idle symbolReelViewportowns: masked, unmasked, dim, spotlight and promoted layers; the mask GraphicsTickerRefowns: every ticker callback it registeredReelSymbolowns: its view container and whatever the subclass allocates in onDestroy()The TickerRef rule
A PixiJS ticker calls a list of functions once per frame, forever, until each one is removed. Forgetting to remove one is the easiest leak to write and the hardest to see: the game keeps running, a little slower, until the dead callback touches something that is gone. The engine's answer is a thin wrapper, TickerRef, that remembers every callback it adds and removes them all in one destroy(). The rule that follows is simple: nobody in the engine calls ticker.add() directly.
Extension points
Five seams are designed to be replaced. Each row says what you would reach for it to do and how to plug your version in.
| Extend | When you want | How |
|---|---|---|
| ReelSymbol | a new way of drawing a cell | subclass it, implement the five required members, and register it with builder.symbols(r => r.register(id, Class, opts)). The symbols page has the lifecycle and every optional hook. |
| ReelPhase<TConfig> | a new stage in the spin | register a factory with builder.phases(f => f.register(...)). Your configurators always run after the tumble and MultiWays defaults. See the spin lifecycle page. |
| SpinningMode | a different idea of what a spin is | pass an instance to builder.spinningMode(mode). |
| FrameMiddleware | a say in which symbols land where | { name, priority, process(ctx, next) }. Lower priority runs first; a middleware that does not call next() stops the rest. Random fill and target placement are themselves middleware. See the frame pipeline page. |
| MaskStrategy | a custom clip shape | { version: 2, build(ctx), update(g, ctx) }, or a DrawableMaskStrategy with draw(g, ctx) so it composes with others. See the viewport page. |
The pages for each seam: symbols, spin lifecycle, the frame pipeline and viewport and masks.
Where this lives
ReelSetBuilder.tsthe builder andbuild()ReelSet.tsthe set, its constructor order anddestroy()Reel.tsone strip, plus the internalOccupiedStubReelViewport.tsthe layers and the mask contractReelAxis.ts,ReelMotion.ts,StopSequencer.ts
spin/SpinController.ts,spin/phases/,spin/modes/symbols/ReelSymbol.ts,SymbolRegistry.ts,SymbolFactory.ts;pool/ObjectPool.tsframe/FrameBuilder.ts,RandomSymbolProvider.tsspeed/SpeedManager.ts,spotlight/SymbolSpotlight.tsevents/EventEmitter.ts,utils/Disposable.ts,utils/TickerRef.ts