Cascade physics
Why survivors without holes below them never move.
In a cascade game (also called a tumble or an avalanche) the reels do not just stop. The winning symbols pop and vanish, the symbols above them drop into the gaps, new symbols fall in from the top to fill the column back up, and if that makes another win the whole thing repeats. Players watch this very closely, because it is where the game feels physical, and there is one mistake that breaks the illusion immediately: a symbol that had nothing removed beneath it twitches, slides or jumps anyway. The eye catches it every time.
That mistake is common because the naive implementation makes it. If you shift every cell up by the number of winners and tween it back down, every symbol in the column moves, including the ones that should have stayed perfectly still. pixi-reels instead works out, for every cell, exactly how far its symbol has to fall, with one pure function called computeDropOffsets in packages/pixi-reels/src/cascade/tumbleAlgorithm.ts. A cell whose distance is zero never even gets an animation job; its view stays exactly where placement put it. This page explains that function, the three phases that animate its answer, the chain that runs cascades until there are no more wins, and how skipping behaves in the middle of all that.
The algorithm, in one column
Figure 1 walks one column through a refill under forward gravity, which is the normal case: symbols settle toward the end of the strip, the bottom of a vertical reel. Five cells, the two winners at cells 1 and 3. Follow the stages left to right: the winners are removed, the survivors pack toward the bottom, and the new symbols fill in from the top. The number beside each cell is how far it moved. Notice that E, which had no winner below it, is marked 0 and is never touched, while A, which had two winners below it, moves two cells.
Figure 2 is the same two winners under reverse gravity, where symbols settle toward the start of the strip instead. The first two stages are identical, so only the last two are drawn. Notice that it is the mirror image: survivors pack toward the top, the new symbols come in at the bottom, and the offsets are negative because the symbols moved toward smaller cell numbers.
The table is the same two examples as numbers, one row per cell of the new grid. originalCell is where each symbol came from, and for a new symbol that is a virtual cell outside the window.
| forward | reverse | ||||||
|---|---|---|---|---|---|---|---|
| cell | id | originalCell | offsetCells | cell | id | originalCell | offsetCells |
| 0 | X (new) | -2 | 2 | 0 | A | 0 | 0 |
| 1 | Y (new) | -1 | 2 | 1 | C | 2 | -1 |
| 2 | A | 0 | 2 | 2 | E | 4 | -2 |
| 3 | C | 2 | 1 | 3 | X (new) | 5 | -2 |
| 4 | E | 4 | 0 (no job) | 4 | Y (new) | 6 | -2 |
computeDropOffsets, exactly
The function takes the number of visible cells, the list of winning cells, and two options: initial, for the very first drop of a spin, and gravity, 'forward' or 'reverse'. It returns one DropOffset per visible cell of the new grid, with the four fields in the table.
| Field | Meaning |
|---|---|
| cell | The visible cell in the new grid. |
| originalCell | Where the symbol came from. For a survivor, its old cell. For a new symbol, a virtual cell outside the window: negative under forward gravity, at or past visibleCells under reverse. |
| offsetCells | cell - originalCell, signed. Zero means do not animate this cell at all. |
| isNew | Whether this is a new symbol. Branch on this, not on the sign of originalCell, which only works under forward gravity. |
Here is how it gets there, in words first. Count the winners; call that winCount (on the initial drop every cell counts as a winner, so winCount is the whole column). List the old cells that did not win, in ascending order; those are the survivors, and there are survivorCount = visibleCells - winCount of them. Now the key observation: after gravity, the survivors keep their order and are packed against the gravity end, and the winCount cells at the other end are the new symbols. Under forward gravity that means cells 0 .. winCount - 1 are new and the rest are survivors; under reverse gravity, a cell is new when cell >= survivorCount.
For a survivor, the i-th one in order lands at cell winCount + i (forward), and it came from the i-th entry of the non-winner list, so its original cell is nonWinnerCells[cell - winCount]; under reverse gravity it lands at cell i and comes from nonWinnerCells[cell]. That is why a survivor with no hole below it never moves: its new cell minus its old cell works out to exactly the number of winners that were between it and the gravity end. E in figure 1 had nothing below it, so its offset is zero. For a new symbol the original cell is simply cell - winCount (forward) or cell + winCount (reverse), a virtual cell beyond the window, so every arrival travels the same winCount cells and the whole fill lands in one beat.
The two options cover the two moments a drop happens. Moment A, the initial drop on a spin, passes initial: true: every cell is new and travels the full visibleCells. Moment B, a refill, passes the cleared cells; an empty list makes every offset 0. initial defaults to false so a reel with no winners cannot trigger a full re-drop by accident. Orientation never reaches the function, only gravity does, and it is exported so you can validate a server-side gravity simulation offline.
The server contract follows from this. In the grid you pass to refill or return from nextGrid, the winners.length cells at the gravity-entry end hold the new symbols and the survivors keep their original order. The engine animates the grid it is given; it does not reorder it. One note on the design record: ADR 010 describes a staggered entrance, with a new symbol at row R starting R + 1 slots up, and uses the v1 names row and offsetRows. The code moves every new symbol a uniform winCount and uses cell and offsetCells. The code is the source of truth here. ADR 010's central rule holds: zero-offset cells are never touched, and the API takes match winners, not a grid diff.
Why winners must be semantic, not diffed
It is tempting to skip the winners list and let the engine compare the old grid with the new one. That cannot work, and one example shows why. Take a column [A, C, X] where X at cell 2 wins. The correct next column is [N, A, C]: one new symbol at the top, the two survivors shifted down by one. A diff reports three changed cells (A became N, C became A, X became C) and would animate three new symbols falling in from above, instead of one new symbol plus two survivors sliding one cell. The API therefore takes a Cell[] of match winners, so the answer is unambiguous. Your detectWinners callback returns the cells your game rules consider winners, nothing else. The four cards below are the cases to check your own implementation against.
One new symbol enters at cell 0 and travels one cell. Every survivor stays put.
Survivors above the winner each fall one cell. Survivors below do not move.
Every survivor falls exactly one cell. The new symbol fills cell 0.
Two new symbols enter, each travelling two cells. No survivor moves.
TumbleConfig
Calling builder.tumble(config) registers the three cascade phases and makes 'cascade' the default spin mode. The config, in packages/pixi-reels/src/cascade/TumbleConfig.ts, holds animation values only: how the old window falls out and how the new one drops in. There are no callbacks in it, because everything you might want to hook is an event. The builder rejects the v1 key names and the v1 cellOrder values. The table lists every key with its default.
| Key | Default | Meaning |
|---|---|---|
| fall.duration / ease / cellStagger | 300 ms / 'sine.in' / 0 | the whole window drops out of the mask on spin() |
| fall.cellOrder | 'auto' | 'auto' starts at the gravity-exit end; 'endFirst' / 'startFirst' name a fixed strip end |
| dropIn.duration / ease / cellStagger | 600 ms / 'power2.out' / 60 ms | the ease deliberately has no overshoot |
| dropIn.cellOrder | 'auto' | the stack fills from the gravity-exit floor |
| dropIn.distance | 'perHole' | 'perHole': each symbol falls exactly as far as its hole. 'auto': full visible height, except refill survivors, which silently use per-hole geometry to avoid a teleport flash. A number: uniform pixels |
| gravity | 'auto' | follow each reel's travel direction; 'forward' settles toward the larger main coordinate, 'reverse' toward the smaller. Independent of travel |
| per-profile overrides | none | speed.tumble.fall / speed.tumble.dropIn merged at each phase entry without mutating the base config |
A few small helpers live beside the config: resolveGravity(g, direction) turns 'auto' into a concrete gravity, gravitySign(g) is +1 for forward and -1 otherwise, resolveCellOrder(order, gravity) turns 'auto' into 'endFirst' under forward gravity and 'startFirst' under reverse, and resolveTumbleConfig, mergeFallConfig and mergeDropInConfig fill in defaults and apply the per-profile overrides. One thing you will not find in the config is a delay between reels. The fall is staggered by speed.spinDelay, and the place and drop-in by the stop delays or by setDropOrder.
The three phases, on a spin and on a refill
A cascade set uses the same phase machinery as a normal set, with different phases. Figure 3 is one reel's phase list for a spin() in cascade mode. Notice that there is no spinning at all: the old window falls out of the mask, the reel waits at speed zero for the result, and then the new window is placed and drops in. Every cascade phase is a ReelPhase with skippable and quickenable set, and its per-tick update() does nothing because the animation is a GSAP timeline.
A refill reuses the last two phases. Figure 4 shows the two ways it can run them. The default, 'combined', places the new column and drops survivors and new symbols together in one motion. The two-stage mode, 'gravity-then-drop', lets the survivors settle first on every reel at once, holds for a beat so the player can see the gaps, and only then reveals the new symbols. Notice that in the two-stage mode the new symbols are placed at alpha 0 during the first stage, so they are already in position when the reveal comes.
In 'gravity-then-drop' the first drop-in runs with the role 'gravity' and emits cascade:gravity:* events instead of the drop-in ones. The hold is gravityHoldMs (250 by default) plus whatever gravityHold adds, after which onGravityComplete is awaited; then the second drop-in, role 'new', reveals the new symbols in place.
The three phases each do one job. The fall (spin/phases/CascadeFallPhase.ts) empties the window. It sets the spinning mode, halts the drive, tells the symbols the spin is starting, merges any speed.tumble.fall override, waits its delay, then emits cascade:fall:start and builds one timeline. Every cell tweens along the main axis by (visibleCells + exitBuffer + 1) * slotPitch, far enough to clear the mask, where exitBuffer is the buffer on the gravity-exit side; each cell gets a cascade:fall:symbol event. When the timeline completes every view goes to alpha 0 and cascade:fall:end fires. A zero duration skips the per-symbol events. On a skip the phase aborts its signal before :end, and emits :end only if :start already fired.
The place (CascadePlacePhase) swaps the identities without moving anything. It re-masks any lifted views, calls placeStrip with the buffer above plus the visible cells (the buffer below is left out so it random-fills; the buffer above is kept because a big-symbol anchor can live there), snaps to the grid, and tells the symbols the spin has ended. Then it runs computeDropOffsets with the resolved gravity: survivors at offset 0 get alpha 1, movers get alpha 0, so nothing flashes at its final position before it has fallen there. It emits cascade:place:end { reelIndex, placedSymbols, isInitial, winnerCells } synchronously, before the drop starts, so a decoration you attach in that handler falls with its symbol. There is no :start.
The drop-in (CascadeDropInPhase) is the animation. It picks its event names from its role ('gravity' emits cascade:gravity:*, 'all' and 'new' emit cascade:dropIn:*), fires :start at once, and builds one job per moving cell (a big-symbol anchor gets one job for the block). Each job works out its start position from the distance mode, moves the view there first and reveals it second, then tweens to the final position with the stagger and order from cellOrder, emitting a :symbol event { symbol, view, reelIndex, cellIndex, duration, ease, offsetCells, signal }. On finish it emits :end. The 'gravity' role calls onReelLanded on the movers only; the other roles call reel.notifyLanded(moverCells), so an untouched survivor never replays a landing. Zero jobs or a zero duration snaps straight to the end.
runCascade, the chain
A single refill is one step. A real cascade keeps going until there are no more wins, and runCascade is the loop that does it. Figure 5 is one trip round that loop, clockwise from the top left. Your detectWinners decides whether there is anything to do; if there is, the winners are presented and destroyed, there is a pause, your nextGrid supplies the refilled column contents, and the engine refills. Notice the two ways out: an empty winners list, or hitting maxChain, both end the chain with a result object.
reelSet.runCascade(options) (core/ReelSet.ts) takes the two callbacks from the figure, detectWinners and nextGrid, the optional hooks presentWinners and onCascade, and the knobs pauseAfterDestroyMs, maxChain, destroyOptions, refillMode, gravityHoldMs, gravityHold, onGravityComplete and signal. The round's signal is forwarded to destroySymbols unless destroyOptions carries its own; a gravityHold given as a function is invoked at gravity end; and the loop checks wasSkipped after every await. After each refill it reads the board back with getVisibleGrid() to feed the next detectWinners.
For one stage, the events arrive in this order: cascade:chain:start, cascade:destroy:start, cascade:destroy:end, spin:start (from the refill), then per reel cascade:place:end, cascade:dropIn:start, the :symbol events and cascade:dropIn:end (with the gravity events first in two-stage mode) and spin:reelLanding / spin:reelLanded, then spin:allLanded, spin:complete and cascade:chain:end. The events page has every payload.
refill checks everything before it changes any state: the grid shape, v1 keys and buffer counts (_assertGrid), that no spin or refill is in flight, that .tumble() was configured, that the column count and visible length match the reels, and that every winner is in range. Only then does it take the spinning state, set the spin mode to 'cascade', build all the frames up front, group the winners per reel in ascending order and emit spin:start. A failure in stage 1 or in the hold of 'gravity-then-drop' emits cascade:gravity:error { error }, logs, and slams. From reading the code, refill() emits spin:start and spin:allLanded, so pin turns and 'eval' pins are probably spent on every refill; that has not been tested.
Abort, skip and slam
Skipping in the middle of a cascade has a few rules of its own, because there is no spin-out to speed up and a chain may have several refills still to come. The table collects them.
| Rule | What it means |
|---|---|
| Per-phase signals | Each fall and drop-in run owns an AbortController, exposed as signal on the cascade:fall:symbol, cascade:dropIn:symbol and cascade:gravity:symbol events. It aborts only on an explicit skip and always before the paired :end event; natural completion drops it without aborting. Hook your per-symbol decoration tweens to it so they stop when the drop is skipped. |
| Your signals mean fast-forward | A signal you pass to destroySymbols, refill or runCascade jumps to the landed state; the promise still resolves, with wasSkipped set. ReelSet.refill also listens for skip:requested and calls abortSlam() on abort. |
| Quicken becomes slam | In cascade mode there is no spin-out to speed up, so a 'quicken' press is turned into a slam, with a one-time quicken-cascade warning. |
| One press auto-slams later refills | The first skip press in a cascade round sets _autoSlamRefills instead of a speed boost; every later refill() in that round lands instantly and skips the phase chain. The flag clears on the next round's spin(). |
| setDropOrder is sticky | setDropOrder('ltr' | 'rtl' | 'all' | number[] | null, stepMs?) applies to every later spin() and refill() by design. The default step is max(stopDelay, 150); the docstring says "150 ms if stopDelay is 0", and the code is the source of truth here. Details on the skipping page. |
The skip paths in full are on the skipping page.
MultiWays interplay
On a MultiWays set the number of visible cells per reel can change between spins, and that interacts with cascades in one specific way: shape changes apply at the start of a spin (ADR 015), never in the middle of a chain. setShape(cellsPerReel) records the target shape, emits shape:changed and migrates pins straight away. It throws if the set was not built with .multiways(), if it is called after setResult() in the current spin, or if a value is outside [minCells, maxCells].
Big symbols plus MultiWays still throw at build. If you read ADR 015, its phase names (DropStartPhase, visibleRows) are the old ones.
CascadeMode is legacy
You may find spin/modes/CascadeMode.ts, a SpinningMode named 'cascade' with a gravity factor of 1.5 whose computeDelta caps the per-frame step at one slot pitch. It is exported, but nothing inside the engine instantiates it. The tumble pipeline is the three phases above, and CascadeFallPhase sets reel.spinningMode only to satisfy the start-phase contract.
API surface
Four public calls cover everything on this page, from a single pop to a whole chain.
| Call | What it does |
|---|---|
| reelSet.destroySymbols(cells, opts?) | The "pop" primitive. Range-checks every coordinate up front, emits cascade:destroy:start { cells }, awaits Promise.allSettled of each symbol's own playDestroy({ delay, signal }) so a subclass can disintegrate in its own style (the default is a roughly 200 ms pop and implode), and lists any rejected cells in cascade:destroy:end { cells, failed? }. Options: delay (seconds, or (cell, i) => seconds, default 0), zIndex (default 1000, not restored, null skips), dim (false; true means 0.35), signal. |
| reelSet.refill({ winners, grid, mode?, gravityHoldMs?, gravityHold?, onGravityComplete?, signal? }) | The "place and drop" primitive. Returns RefillResult { winnersRefilled, finalGrid, wasSkipped, skipContext, duration }. |
| reelSet.runCascade({ detectWinners, nextGrid, ... }) | The chain orchestrator described above. |
| computeDropOffsets(visibleCells, winnerCells, opts?) | The algorithm itself, exported so you can test a server-side gravity simulation against it. |
The cascades guide walks a first chain and the cascade recipes show destroy presentation, two-stage gravity and per-symbol decorations.
Where this lives
tumbleAlgorithm.tscomputeDropOffsets, DropOffset, CellTumbleConfig.tsTumbleConfig, resolveGravity, gravitySign, resolveCellOrder, merge helpers
phases/CascadeFallPhase.ts,CascadePlacePhase.ts,CascadeDropInPhase.tsSpinController.tsrefill, the cascade branch of _startReel, auto-slammodes/CascadeMode.tslegacy
destroySymbols,refill,runCascade,setDropOrder,setShape
010-cascade-physics.md(table and names out of date),015-cascade-multiways-interplay.md