pixi-reels
All mechanics

Mechanics

Nudge

Push a reel that has already stopped up or down a few places to pull a symbol into view.

Demos

Each demo shifts a reel that has already landed by a few positions and brings in symbols you choose. The first one is a single nudge. The rest cover nudging several reels, presenting the win, big symbols, other reel directions and cutting a nudge short.

Single nudge#

After the reels land, reel 1 nudges 'forward' by one and a wild enters at the top, then reel 3 nudges 'reverse' by one and a wild enters at the bottom. incoming lists the symbols in their final order on the strip, top to bottom on a vertical set.

Loading recipe…

Several reels#

The same row of wilds nudged into reels 1 to 3 in three ways. The engine output is the same each time; only the pacing changes.

One after another#

Each await waits for the previous reel to land, so the player sees three separate reveals. The total time is the number of reels times the duration.

Loading recipe…

All at once#

Promise.all starts every tween on the same frame and the wilds arrive together. The total time is one duration.

Loading recipe…

Staggered#

Promise.all with a per-reel startDelay. The tweens run at the same time but start one after another, so the wilds arrive in a wave. Bad arguments still throw at the call; only the movement waits.

Loading recipe…

Spotlight after a nudge#

The reels land one wild short of a line. Three reels nudge in parallel to complete it, then SymbolSpotlight presents the new winning cells.

Loading recipe…

Big symbols#

A 1xH block on the target reel moves as one piece. In the first demo a 1x2 wild nudges down by two, so its lower half moves into the buffer below the window, then up by one into full view. In the second the block nudges up so only its lower half shows, then back down into full view.

Only blocks one reel wide (size.reels === 1) can be nudged. A block that spans reels throws.

Loading recipe…

Loading recipe…

Other reel directions#

direction is relative to the reel’s own axis, so the nudge code is the same on any set. What changes is where on screen the new symbol enters.

Horizontal set#

On .orientation('horizontal') a reel is a screen row, so a nudge shifts it sideways. One press nudges row 0 'forward', where a wild enters at the left edge, and row 2 'reverse', where a wild enters at the right. incoming reads left to right here.

Loading recipe…

Reels that spin up#

Two wilds land on the middle line and the third stops one cell below it. On a .direction('reverse') reel a 'forward' nudge travels upward, so the incoming symbol enters at the bottom cell and the wild rolls onto the line, which then lights up.

Loading recipe…

Cutting a nudge short#

Both ways end with the strip where the nudge was going. They differ in what the promise does.

Skip#

reelSet.skipNudge(reel) jumps a running nudge to its end. nudge() resolves as usual, so the success path still runs. Use it when the win plays next.

Loading recipe…

Abort#

Abort through NudgeOptions.signal. The strip still snaps to its landed position, but nudge() rejects with AbortError and nudge:cancelled fires. Use it when you are tearing the feature down.

Loading recipe…

Concept

Nudge
Shift a reel forward or back by one or more positions after it has stopped, bringing in symbols you supply.

A nudge moves one reel a few cells after it has landed, and brings in symbols you choose. The classic use is a near-miss: the reels land one symbol short, then one reel nudges by one cell to reveal the symbol that was missing.

await reelSet.spin();

await reelSet.nudge(2, {
  distance: 1,
  direction: 'forward',
  incoming: ['wild'],
});

Reel 2 moves one cell. Everything on it shifts along, the last symbol leaves the window, and the wild arrives at the front.

Loading recipe…

The contract#

interface NudgeOptions {
  /**
   * Number of full positions to shift. Positive integer, strictly less than
   * the reel's total strip capacity (bufferStart + visibleCells + bufferEnd).
   */
  distance: number;
  /**
   *  - 'forward': the way this reel travels; new symbols enter at its
   *    feed edge.
   *  - 'reverse': the other way; new symbols enter at the opposite edge.
   *
   * Relative to the reel, not the screen. On a reel built with
   * direction('reverse'), 'forward' nudges upward.
   */
  direction: 'forward' | 'reverse';
  /**
   * Symbol ids in top-down order of their final on-strip position,
   * including any overflow into the off-screen buffer. Length must equal
   * `distance` exactly.
   */
  incoming: string[];
  /** Tween duration in ms. Default: `200 * distance`. */
  duration?: number;
  /** GSAP ease name. Default: `'power2.out'` (smooth deceleration, no overshoot). */
  ease?: string;
  /** Delay before the tween begins (ms). Sugar for staggered Promise.all. */
  startDelay?: number;
  /** Abort the nudge mid-flight. Strip still snaps to landed position. */
  signal?: AbortSignal;
}

reelSet.nudge(reel: number, options: NudgeOptions): Promise<{ symbols: string[] }>;
reelSet.skipNudge(reel?: number): void;

The promise resolves with the reel’s new visible cells, in order, which you can feed straight into win detection. It rejects with an AbortError if the signal aborts or the set is destroyed mid-tween.

How incoming lays out#

For a 3-cell reel landed on ['A', 'B', 'C'] (first, middle, last):

CallNew visible (first to last)
nudge(r, { distance: 1, direction: 'forward', incoming: ['X'] })['X', 'A', 'B']
nudge(r, { distance: 2, direction: 'forward', incoming: ['X', 'Y'] })['X', 'Y', 'A']
nudge(r, { distance: 1, direction: 'reverse', incoming: ['X'] })['B', 'C', 'X']
nudge(r, { distance: 2, direction: 'reverse', incoming: ['X', 'Y'] })['C', 'X', 'Y']

The first entry always ends up nearest the start of the reel and the last entry nearest the end.

A nudge further than the visible cell count pushes the overflow into the buffer on the matching side. With 'forward', the trailing entries spill into the buffer at the exit edge. With 'reverse', the leading entries spill into the other one. Nothing is thrown away. Every entry stays on the strip, ready for a follow-up nudge or the next spin’s opening frame.

A distance equal to or larger than the strip capacity throws, because a full rotation would silently overwrite a pre-placed buffer entry.

Sequential or parallel#

One nudge moves one reel. When several reels nudge, you choose how to start them. The engine output is the same either way; only the pacing differs.

Sequential#

Loading recipe…

for (const reel of [1, 2, 3]) {
  await reelSet.nudge(reel, { distance: 1, direction: 'forward', incoming: ['wild'], duration: 480 });
}

Each await waits for that reel to land, so the player sees reel 1’s wild before reel 2 starts. The total time is the number of reels times the duration.

Parallel#

Loading recipe…

await Promise.all(
  [1, 2, 3].map((reel) =>
    reelSet.nudge(reel, { distance: 1, direction: 'forward', incoming: ['wild'], duration: 480 }),
  ),
);

All the tweens start on the same frame and the whole line arrives together. The total time is one duration, however many reels.

Stagger#

The startDelay option gives you a wave without a loop:

await Promise.all(
  [1, 2, 3].map((reel, i) =>
    reelSet.nudge(reel, { ...opts, startDelay: i * 80 }),
  ),
);

The tweens start at 0, 80 and 160 ms and run concurrently. Validation still throws synchronously at the call site. Only the movement is delayed.

Big symbols on the reel#

A tall block moves as one piece, as long as the whole block is still on the strip afterwards:

DirectionSurvival condition
'forward'anchorStripIdx + h - 1 + distance < total
'reverse'anchorStripIdx - distance >= 0

Here total is the strip capacity (buffer start plus visible cells plus buffer end) and anchorStripIdx counts from 0 at the outermost start-buffer cell, so the index of visible cell 0 equals the buffer start count.

A block may sit partly in a buffer and still render correctly. The engine sizes the anchor to span the whole block wherever it lives, and the mask clips the rest. This is how a tail reveal works: land a tall wild with its anchor in the buffer, nudge, and the rest of it moves into view.

A block wider than one reel always throws. Nudging one reel would tear the block off its cells on the next one.

// A 1x2 wild sits at visible cell 1 with its tail in bufferEnd.
// Nudge back by 1 and the whole block lands at cells 0 and 1.
await reelSet.nudge(2, { distance: 1, direction: 'reverse', incoming: ['filler'] });

Skip and abort#

There are two ways to cut a nudge short.

// 1. Skip: fast-forward to landed. The promise resolves normally.
const p = reelSet.nudge(2, { ...opts });
button.onclick = () => reelSet.skipNudge(2);
const { symbols } = await p;
// 2. Abort: reject with AbortError. The strip still snaps to landed.
const controller = new AbortController();
const p = reelSet.nudge(2, { ...opts, signal: controller.signal });
button.onclick = () => controller.abort();
try { await p; }
catch (e) { if (e.name !== 'AbortError') throw e; }

The difference is what happens to the promise. skipNudge resolves it, so your success path runs. An abort rejects it and fires nudge:cancelled, so your error path runs. Skip when the win plays next, and abort when you are tearing the feature down.

Either way the strip lands where it was going to land. A nudge never stops half-tweened.

Events#

EventPayloadWhen
nudge:start({ reelIndex, distance, direction })Pre-placement is done and the tween is about to begin.
nudge:complete({ reelIndex, distance, direction, symbols })The strip snapped to the post-nudge grid. symbols is the new visible column.
nudge:cancelled({ reelIndex, distance, direction, reason })The signal aborted or the reel was destroyed mid-tween. Never fires together with nudge:complete; the promise rejected instead.
phase:enter (per reel)('nudge')Mirror of nudge:start, on the affected reel’s bus.
phase:exit (per reel)('nudge')Mirror of nudge:complete.

The per-reel landed event does not fire on a nudge. It belongs to the spin pipeline. Listen to nudge:complete instead.

reelSet.events.on('nudge:complete', ({ reelIndex, symbols }) => {
  console.log(`reel ${reelIndex} now reads`, symbols);
  // Re-run win detection on reelSet.getVisibleGrid() here.
});

When nudge() throws or rejects#

Bad arguments throw at the call. Cancellation rejects later.

It throws synchronously when:

  • The reel set is spinning, refilling, or in a cascade.
  • reel is out of range.
  • The target reel has an active pin. Call unpin first.
  • distance is below 1, not an integer, or at least the strip capacity.
  • direction is neither 'forward' nor 'reverse'.
  • The length of incoming differs from distance.
  • An incoming id is not registered, or is a big symbol.
  • A block on the target reel would not survive the rotation.
  • A cell on the target reel belongs to a block wider than one reel.

It rejects with an AbortError when:

  • The signal aborts before or during the tween.
  • reelSet.destroy() is called mid-tween.

A nudge touches one reel. The other reels, their pins and any spotlight are left alone.

Recipes#

API

Every exported name the concept, the demos and their sources use, with the one-line summary from the generated reference.

  • Reelclass

    One vertical column of a slot board.

  • The configurator you call before every reel set.

  • Per-symbolId cache of "spin textures". flat snapshots a reel shows instead of the live symbol (Spine skeleton, animated sprite, ...) while it spins.

  • Wraps any ReelSymbol and swaps it for a cached snapshot texture while the reel spins. "spin static, not Spine."

  • The "we just won" visual primitive.

  • stepfunction

    Build a PhaseStep.

  • NudgeOptionsinterface

    Options for Reel.nudge() / ReelSet.nudge(). a post-stop reposition that shifts the reel by distance symbol positions and reveals new caller-supplied symbols.

  • Standard high-card deck for prototyping. Each card has its own color so a full grid is visually unambiguous at a glance.

  • Built-in speed profiles covering common slot game needs.

  • A pale-yellow WILD card for sticky/expanding-wild prototypes.

Questions

From the FAQ, the questions tagged with this mechanic. Open one here, or follow it to its own page.

How do I abort a spin that is already in flight?open

Pass an AbortSignal via spin({ signal }) and call controller.abort(); the spin promise rejects with an AbortError.

Question page
How do I nudge a reel by one position after it stopped?open

reelSet.nudge(col, { ... }) shifts a reel up or down after it landed, feeding caller-supplied incoming symbols.

Question page