pixi-reels
Reference
Objects

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.

ReelSetBuilderthe only new you writebuild()ReelSeta PIXI.Container, DisposableReelViewportthe only display child5 layers, 1 maskSpinControllerowns the TickerRefactive phase per reelSpeedManagerthe speeds mapbuilt in the ctorSymbolSpotlightdim + spotlightbuilt in the ctorSymbolFactoryObjectPool<ReelSymbol>keyed by symbol idFrameBuilderRandomSymbolProvidermiddleware chainEventEmitterReelSetEventsits own buspins, ReelFactoryMap<key, CellPin>closure from build()Reel[]one per reels(n), plus addReels()containers sit in the viewport
What the ReelSet owns after build(). Eight subsystems plus the reels; the next figure opens one reel.

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.

Reel iimplements DisposableReelAxisreelAxis(orientation, dir)toScreen, mainPropReelMotionmoves the strip every tickindex -> position, wrapsStopSequencerthe landing queuenext() on every wrapsymbols: ReelSymbol[]buffer + visible + bufferfrom the SymbolFactorycontainerPIXI.ContainerzIndex = +/- reelIndexeventsEventEmitter<ReelEvents>phase:*, landed, symbol:created
What one Reel owns. Its container is a display child of viewport.maskedContainer; the Reel object itself belongs to the ReelSet.
Public APIthe builder; you construct this
ConductorSpinController drives every reel
Subsystemsowned by the ReelSet, destroyed with it
Per reeldark boxes are owned by one Reel

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.

ReelSetBuilderbuilder

A 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 root

The 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 strip

One 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 layers

The 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.

ReelAxisorientation

The 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 physics

Moves 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 queue

A 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.

SpinControllerconductor

Runs 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.

ReelPhasestate

Abstract 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.

SpinningModestrategy

What 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().

SpeedManagertempo

Named 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 cell

One 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 / SymbolFactorypool

SymbolRegistry 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 + middlewarepipeline

Decides 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.

SymbolSpotlightwins

The 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 / sub

Typed, 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 ticker

A wrapper around PIXI.Ticker that remembers every callback it adds and removes them all on destroy(). Nobody in the engine calls ticker.add() directly.

Disposableinterface

The 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 + HeadlessSymboltests

The 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.

1. _spotlight.destroy()spotlight tweens and overlay containers go first2. _spinController.destroy()its TickerRef removes every ticker callback it added3. reel.destroy() for each reelmotion, sequencer, symbols and the reel container4. _destroyAllPinOverlays()pin:overlayDestroyed per overlay, then each is released to the pool5. _symbolFactory.destroy()the ObjectPool disposes every idle symbol6. _viewport.destroy()promotedLayer.detachAll() first, then super.destroy({ children: true })7. _pins.clear()the pin map is emptied; no events8. _bus.emit('destroyed')expand() listens for this to drop its abort listener9. _bus.removeAllListeners()the bus is gone after this line10. super.destroy({ children: true })the PixiJS Container teardown
ReelSet.destroy(), one box per line of source. Each step only touches things the previous steps 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, events
Reelowns: axis, motion, stopSequencer, symbols, container, events, occupied stubs
SpinControllerowns: TickerRef, the active phase per reel, cached frames
SymbolSpotlightowns: gsap timelines, the dim request, reparented winner views
SymbolFactoryowns: ObjectPool<ReelSymbol>; pool.destroy() disposes every idle symbol
ReelViewportowns: masked, unmasked, dim, spotlight and promoted layers; the mask Graphics
TickerRefowns: every ticker callback it registered
ReelSymbolowns: 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.

ExtendWhen you wantHow
ReelSymbola new way of drawing a cellsubclass 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 spinregister a factory with builder.phases(f => f.register(...)). Your configurators always run after the tumble and MultiWays defaults. See the spin lifecycle page.
SpinningModea different idea of what a spin ispass an instance to builder.spinningMode(mode).
FrameMiddlewarea 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.
MaskStrategya 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

packages/pixi-reels/src/core/
  • ReelSetBuilder.ts the builder and build()
  • ReelSet.ts the set, its constructor order and destroy()
  • Reel.ts one strip, plus the internal OccupiedStub
  • ReelViewport.ts the layers and the mask contract
  • ReelAxis.ts, ReelMotion.ts, StopSequencer.ts
elsewhere
  • spin/SpinController.ts, spin/phases/, spin/modes/
  • symbols/ReelSymbol.ts, SymbolRegistry.ts, SymbolFactory.ts; pool/ObjectPool.ts
  • frame/FrameBuilder.ts, RandomSymbolProvider.ts
  • speed/SpeedManager.ts, spotlight/SymbolSpotlight.ts
  • events/EventEmitter.ts, utils/Disposable.ts, utils/TickerRef.ts