pixi-reels
Reference
Start here

Overview

The main parts of pixi-reels and how they are wired together.

A slot machine looks simple from the outside: press a button, five columns blur, five columns stop, you see a grid. Inside a real game that moment is a surprising amount of coordination. Something has to fetch the result from a server while the reels are already moving, hand each column the exact symbols it must land on, stop them one after another with a satisfying bounce, let one column hesitate for drama, and survive a player who taps the button twenty times a second. pixi-reels is that machinery, packaged so you can build the game around it instead of building it again.

Three rings

It helps to picture the library as three rings around your game. The innermost ring is the builder: a fluent object that collects your configuration and, in one build() call, checks it and constructs everything. The middle ring is the reel set: the container that owns the reels, the spin controller, the speed profiles and the win spotlight. The outer ring is optional tooling, testing and debug, that attaches from the outside and never ships in your bundle unless you import it.

Figure 1 is the middle ring after build() returns. The boxes inside the ReelSet are its subsystems; each one has its own page in this tour.

Your gamespin(), setResult(), eventsReelSetBuilder.reels(5).visibleCells(3).symbols(...).build()PIXI.Tickerapp.ticker, via TickerRefgsapper set, via .gsap(instance)build()ReelSeta PIXI.ContainerSpinControllerruns the phasesper reelSpeedManagernormal, turbo,super turboFrameBuilderwhich symbolsland whereSymbolFactoryone ObjectPoolper symbol idSymbolSpotlightdim losers,promote winnersEventEmitter59 typed eventsspin:*, skip:*, ...ReelViewportthe only display child: five reels under one mask
What you construct, and what build() hands back. The ReelSet owns six subsystems and one display child, the viewport.
  • SpinController is the conductor. It walks each reel through its phases (start, spin, maybe anticipation, stop), holds every reel back until your result has arrived, and turns a skip press into a slam or a quicken. It never draws and never chooses an outcome.
  • SpeedManager holds named timing profiles, normal, turbo and super turbo out of the box, and lets you tune any phase at runtime.
  • FrameBuilder turns your result grid into the exact list of symbols each reel will show, buffers included, before the reel starts stopping.
  • SymbolFactory hands out symbol instances from a pool, one pool per symbol id, so a five-second spin allocates nothing.
  • SymbolSpotlight is the win presentation primitive: dim the losers, lift the winners above the mask, play their animation.
  • EventEmitter is how the set talks back. Fifty-nine typed events, from spin:start to pin:expired.

What a reel is

The word "reel" usually means a column on screen. In pixi-reels a reel is a strip: an array of symbols that is longer than the window you see. The extra symbols sit just outside the visible area, above and below it, so there is always something ready to scroll in. The window itself is a mask on the viewport. Figure 2 shows the five strips under that mask.

ReelViewportmaskedContainerReel 0ReelAxisReelMotionStopSequencerReelSymbol[]Reel 1ReelAxisReelMotionStopSequencerReelSymbol[]Reel 2ReelAxisReelMotionStopSequencerReelSymbol[]Reel 3ReelAxisReelMotionStopSequencerReelSymbol[]Reel 4ReelAxisReelMotionStopSequencerReelSymbol[]dashed = the visible window (the mask)the symbols above and below it are buffer cells, drawn but clipped
Inside the viewport. Each Reel is a strip longer than the window; the mask hides the buffer cells above and below it.

Each strip carries three small helpers. ReelAxis knows which screen axis the strip travels on and in which direction, so the same code runs a vertical, horizontal or reversed reel. ReelMotion owns the position of every symbol and derives it from the array index on every frame, which is why reels never drift. StopSequencer is the short queue of symbols the reel must land on, handed out one at a time as symbols wrap around. The motion page walks through one frame of all three.

Things that attach from outside

Two subpaths exist so you can look inside without shipping the tools. pixi-reels/testing swaps exactly two things, the Pixi ticker and the symbol art, and leaves everything else real, which is why a whole spin can run in Node in a few milliseconds. pixi-reels/debug draws what the engine knows (cells, buffers, axes, a phase timeline) onto the canvas, and enableDebug() in the main entry exposes the same facts as JSON for anyone, human or agent, who cannot see a canvas.

ReelSetthe thing onyour stagepixi-reels/testingFakeTickertick(ms) by handHeadlessSymboldraws nothingcreateTestReelSetspinAndLand,expectGridpixi-reels/debugdebugOverlay12 drawn layersSpinMetricsrounds and phasesenableDebugmain entry:JSON snapshots
Two subpaths attach from outside and never ship unless imported. Testing swaps the ticker and the art; debug only reads.
Entry pointthe one class you construct yourself
ConductorSpinController drives every reel
Subsystemsowned by the ReelSet, destroyed with it
Optional subpathstesting and debug attach from outside

One spin, end to end

Here is the story the rest of this tour tells in detail. You call spin(). Each reel starts a little after the previous one, so the kickoff looks staggered. Meanwhile your code asks the server for the outcome and calls setResult() with the grid. The controller waits until every reel is actually spinning and until each has spun for a minimum time, then lets them stop one by one. As a stopping reel scrolls, the symbols it must land on are swapped in at the top edge, one per wrap, until the last one is in place; the reel snaps to the grid and bounces. When the last reel has bounced, the promise from spin() resolves with the grid and the set emits spin:complete.

If the player presses skip, the controller either slams (every reel lands on its result this frame) or quickens (the delays are cut, the landing still plays), depending on what you asked for. If a reel was set up to tease, it slows down and holds before it stops, and you can protect that tease from the first skip press. All of that is covered on the spin lifecycle, timeline, skipping and anticipation pages.

Where the code lives

You rarely need to open these files, but it helps to know the map when a stack trace points into the library.

packages/pixi-reels/src/
  • core/ the set, the builder, one reel and its motion, axis, curve and viewport
  • spin/ the controller, the phases and their steps, the spinning modes
  • symbols/ the symbol base class and its sprite, animated, Spine and card flavours, plus the registry and factory
  • frame/ how a result grid becomes a strip of symbols
  • config/ types, defaults, the speed presets
  • speed/, spotlight/, wins/ timing profiles and win presentation
  • cascade/, board/, pins/ tumble physics, boards and Hold & Win, sticky cells
  • events/, utils/ the typed emitter, the ticker wrapper, gsap plumbing, notices
  • debug/, testing/ the two subpaths
apps/site/src/runtime/
  • BlurSpriteSymbol.ts a sprite symbol that swaps to a motion-blur texture while spinning
  • CoinSymbol.ts a coin drawn with Graphics, for Hold & Win demos
  • holdAndWinFx.ts coin waves and collect flights
  • prototypeSpriteLoader.ts the open-licensed symbol atlas the demos use
  • spineSets.ts the bundled Spine sets behind one interface
packages/cheats/src/
  • cheats.ts forced results for demos and tests
  • seededRng.ts a tiny seeded random number generator

The recipe runtime and the cheats package are reference code, not library API. They live outside the package on purpose so you copy what you need into your own game and own it.

Which way the imports point

One rule keeps the library easy to reason about and lets the testing subpath be dropped from your bundle: imports only ever point down the stack in figure 4. The types and the event emitter know nothing about reels; reels know nothing about the controller; the controller knows nothing about the set that owns it.

config, events, utilstypes, DEFAULTS, EventEmitter, TickerRef, gsappool, symbols, frameObjectPool, ReelSymbol, FrameBuildercore, per reelReel, ReelMotion, ReelAxis, ReelViewportspinphases, modes, SpinControllercore, the setReelSet, ReelSetBuilderspotlight, wins, boardpresentation on top of the set
Imports only point downward. No cycles, which is what keeps the testing subpath tree-shakeable.

Read on in order, or jump to the page that answers your question. Every page opens with the idea in plain words, then shows it, then names the code.