pixi-reels
All mechanics

Mechanics

Spin feel

Tune how a spin starts and stops: the stagger between reels, a wind-up, the kick on landing.

Demos

These demos change how a spin starts and stops. The first two react to a reel landing. The rest edit the step lists the built-in phases run.

Landing#

Landing events#

spin:reelLanding fires on the frame a reel reaches its result: the strip has snapped, every symbol has been told it landed, and the bounce is about to start. spin:reelLanded fires once the bounce has settled, a whole bounceDuration later, or on the same tick after a slam. Hang anything tied to the landing itself on the first one. The demo grows a takeover plate over the copy reels on spin:reelLanding and prints the gap between the two events.

Loading recipe…

Spine landing animation#

Each symbol hears the same moment through onReelLanded(ctx), with the reel and cell it landed in. A Spine symbol’s autoPlayLanding can be a function of that context. It returns true for the configured landing animation, false for none, or an animation name to play something else. Here the copy reels land with no animation, so nothing competes with the takeover, and the last two reels play a reveal as their landing.

Loading recipe…

Assets provided by Thunderkick

Editing the step lists#

The built-in phases run named step lists. StartPhase runs delay, launch, pull, accelerate, announce, StopPhase runs delay, spinOut, land, bounce, and AnticipationPhase runs tease. Registering a phase with f.register('stop', StopPhase, { steps }) passes you the list before it runs. Each demo below changes it with one insertBefore, insertAfter or replaceStep call, or builds the list by hand. Slam and quicken keep working because the waits stay marked cut. The step API is on the Phases page.

Landing kick#

One step after land and before bounce. The reel set kicks and a puff of dust spreads under the reel, harder on the last one. The step returns nothing, so the bounce starts on the same frame. If it returned the tween, the phase would wait for it before bouncing. That return value is what decides whether a step is an effect or a beat.

A slam lands the reel through onSkip, not through the list, so a step after land does not run on a slam. Effects that must also play on a slam belong on spin:reelLanded. A quicken keeps the list.

Loading recipe…

Stagger curves#

The flat stagger arrives as ctx.config.delay, and the delay step is the only place it is used. So a curve is one replaceStep per phase. Here the start ripples out from the middle reel, and the gaps between stops grow, so reels 1 to 3 land quickly and reel 5 hangs. The profile still sets the unit. The second line of the readout shows measured landings, not the schedule.

Keep { cut: true } on the replacement. It is a wait, and a quicken press has to cut it the same way it cuts the flat one.

Loading recipe…

Wind-up launch#

The built-in pull moves the reel back two pixels. This demo replaces it with a pull of most of a cell, inserts a hold after it, and leaves accelerate as it is, so the reel accelerates from wherever the pull left it. Tap the readout to turn the wind-up off and compare.

Handle both motion models the way the built-in step does. Under the drive model, set a targetSpeed and wait. Under the tween model, tween reel.speed. reel.hasDrive tells you which one is active.

Loading recipe…

Extra wait on the last reel#

Every reel runs the same list, so a beat for one reel is a step that does nothing on the others. suspense waits 700 ms before reel 5’s spin-out and returns at once on the other reels. The backlight pulses while it waits.

A step that starts something has to stop it on every way out. ctx.wait resolves early when the step is cut, and ctx.signal fires when it is cancelled, so one stop call covers the natural end, a quicken and a slam.

Loading recipe…

Spotlight around the tease#

AnticipationPhase runs one step and is created only on the teased reel. To shade the other reels while the tease runs, build the list by hand around the built-in step: [dim, ...steps, lift]. Both added steps are awaited, 150 ms each, so the shade is on before the reel starts to crawl and off before the stop phase takes over.

A slam cancels the list in flight and lift never runs, so also clear the shades on spin:complete. A quicken cuts the tease step and lift still runs.

Loading recipe…

Steps that read the speed profile#

Per speed mode#

ctx.profile is the profile the game registered under the active speed name, custom fields included. A breath step before the spin-out and a glow step after land both read it, so normal gets both and turbo gets neither, and the glow’s fade follows bounceDuration. Tap the readout to switch speeds. The skip button here calls requestSkip({ mode: 'quicken', speed: 'turbo' }), which switches the profile the same way.

Do not check for turbo inside a step. Put the decision on the profile, and every speed mode you add later carries its own setting.

Loading recipe…

Profile sections#

The demo above puts a step’s settings on the profile as flat fields. That works, but every phase sees them and nothing says which phase they belong to. A section does. Both steps here are inserted into StopPhase, so their settings live under stop, keyed by step name. The whenAnticipated half is merged on top for a reel that teased, so reels 4 and 5 land with a deeper bounce and a heavier impact, and the same step draws them amber based on ctx.anticipated. Nothing checks the speed name.

stop: {
  steps: { breath: { duration: 140 }, impact: { lift: 8, duration: 420 } },
  whenAnticipated: { bounceDistance: 30, steps: { impact: { lift: 24 } } },
}

A step reads its own entry as ctx.step, in segment order. One object in the profile arrives as one entry; a list is for a step written to read several segments. Declare the two names once by merging them into StopSteps, and stop.steps is type-checked and autocompleted like the built-in steps.

whenAnticipated applies only to a tease that ran to the end. Press skip mid-tease and that reel uses the section’s base settings (blue puff, small lift), because the press cut the tease the variant is there to follow.

Loading recipe…

Concept

Speed modes
The three built-in speed profiles, switching between them, and writing your own.

A speed profile holds the numbers that decide how a spin feels, such as the acceleration, the spin speed, the stagger between stops and the bounce.

The three defaults#

import { SpeedPresets } from 'pixi-reels';

// SpeedPresets.NORMAL        relaxed feel
// SpeedPresets.TURBO         faster stop, short acceleration
// SpeedPresets.SUPER_TURBO   almost instant

A builder with no .speed() call gets NORMAL under the name 'normal'.

Switch at runtime#

reelSet.speed.addProfile('turbo', SpeedPresets.TURBO);
reelSet.setSpeed('turbo');
reelSet.events.on('speed:changed', (p, prev) => console.log(p.name, prev.name));

Custom profile#

const CINEMATIC: SpeedProfile = {
  name: 'cinematic',
  spinDelay: 280,
  spinSpeed: 38,
  stopDelay: 180,
  anticipationDelay: 1200,
  bounceDistance: 14,
  bounceDuration: 260,
  accelerationEase: 'power3.in',
  bounceEase: 'elastic.out(1, 0.5)',
  accelerationDuration: 420,
  minimumSpinTime: 1400,
};

builder
  .speed('cinematic', CINEMATIC)
  .initialSpeed('cinematic');
Sound
Attach a table of sound cues to a reel set's events, with a port for @schmooky/zvuk.

The engine fires events for each moment of a round, and your audio engine plays sounds. attachReelSounds connects the two with a table that says which sound plays on which event, when a loop starts and when it fades out.

The cue table#

import { createEngine } from '@schmooky/zvuk';
import { attachReelSounds, zvukPort } from 'pixi-reels';

const engine = createEngine({ buses: { reels: {}, anticipation: {}, wins: {}, ui: {} } });
await engine.unlock(); // from a gesture
await engine.loadSound('spin', ['/sfx/spin.webm', '/sfx/spin.m4a'], { bus: 'reels' });
await engine.loadVariants('reel-stop', [
  ['/sfx/reel-stop.1.webm', '/sfx/reel-stop.1.m4a'],
  ['/sfx/reel-stop.2.webm', '/sfx/reel-stop.2.m4a'],
], { bus: 'reels' });
// ... anticipation, skip, win, pop

const sounds = attachReelSounds(reelSet, zvukPort(engine), {
  spin: { play: 'spin' },
  reelStop: { play: 'reel-stop', pitch: { jitter: 0.04 },
              delay: ({ profile }) => profile.bounceDuration / 2000 },
  anticipation: { loop: 'anticipation', fadeIn: 0.12, fadeOut: 0.25,
                  pitch: ({ order }) => 1 + 0.08 * order },
  skip: { play: 'skip' },
  win: { play: 'win' },
  cascadeDestroy: { play: 'pop' },
});

sounds.destroy(); // when the reel set goes

The demos on this site run a table like this one. reelSounds(reelSet) from @pixi-reels/kit/sound attaches it to a set, using one audio engine for the whole page, and boardSounds(board) does the same for a Hold & Win board. The Sound button under a demo mutes it. The files load on the first press.

The spin cue plays once per spin. A loop under every spin (spin: { loop: 'spin-loop', fadeIn: 0.05, fadeOut: 0.08 }) is supported and fades out on the last landing, but on a page with many demos it gets tiring. The reel stop sounds are enough to mark the rhythm.

The beats#

CueStarts onA loop ends onContext
spinspin:startspin:allLanded
reelStopspin:reelLanding, on every landing path, cascade refills includedreelIndex
anticipationanticipation:reel, one per teasing reelthat reel’s anticipation:reelEndorder, total, reelIndex
skipskip:requested
winspotlight:start, and win:group per presented win
cascadeDestroycascade:destroy:start
on[event]the named eventits until event

Every context also carries speed (the active profile’s name), profile (the profile itself) and mode ('standard', or 'cascade' for a tumble and its refills).

The default table the demos run uses on for events outside the spin lifecycle. It plays a shove on nudge:start, a tick on column:set when a symbol splits or a column changes, a rising sweep when a set gains cells or reels (expand:stepAdded, reels:added, rows:added), and a soft pop on pin:placed.

A Hold & Win board#

attachBoardSounds(board, port, cues) is the same table over a board’s beats: featureEnter, respinStart (a loop that runs until respin:end), cellLanded (with reelIndex, cell and hit), coinLocked, boardFull, featureEnd, and on for any other board event. The demos play a quiet kick per respin, a thud when a coin lands, a ring a moment after it locks, and the win sound once when the feature ends. Empty cells land without a sound.

A cue is { play: name } for a one-shot or { loop: name, fadeIn, fadeOut } for a bed. volume and pitch take a number, a { base, jitter } spread so repeated thuds do not sound cloned, or a function of the context. The tease cue above climbs about a semitone per reel, and a spin cue can read speed to pitch up in turbo. delay is the time in seconds between the event and the sound. The demos delay the thud by half the profile’s bounceDuration, which is when the reel reaches the bottom of its bounce. Without the delay it would play on the frame the reel snaps. when(ctx) keeps a cue quiet. On a tumble, where the symbols drop in one by one, the demos play the kick and the thuds at half level with no delay.

Loops are tracked per event, so there is one tease loop per reel. They fade out when their beat ends and stop at once on destroy() or when the reel set is destroyed.

Any engine#

attachReelSounds only needs a ReelAudioPort: a play(name, { bus, volume, pitch }) method and a loop(name, { ..., fadeIn }) method that returns { stop({ fade }) }. zvukPort is that port over a zvuk engine. A variants set plays its next take, and a missing name is skipped with one warning. Wrap Howler or raw Web Audio the same way.

API

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

  • Anticipation phase: the tease before a reel stops.

  • One visible cell on a reel. the thing that actually draws.

  • The PhaseCardSymbol class in the pixi-reels API.

  • ReelSetclass

    The whole slot board as one object.

  • The configurator you call before every reel set.

  • ReelSymbol implementation using Spine 2D skeletons.

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

  • Accelerates the reel from rest to full spin speed.

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

  • Stops the reel on the target frame.

  • Snap a table of cues onto a Hold & Win board. Every cue sees the board's active speed name. Returns a handle whose destroy() detaches every listener and stops…

  • Snap a table of cues onto a reel set. Every cue sees the active speed profile and the spin's mode. Returns a handle whose destroy() detaches every listener…

  • insertAfterfunction

    A copy of steps with added placed after the step called name. Throws on an unknown name.

  • insertBeforefunction

    A copy of steps with added placed before the step called name. Throws on an unknown name.

  • Bake spin textures for every symbolId up front (at load or between rounds) so the first spin never pays a capture hitch. Ids that already have a user-provided…

  • replaceStepfunction

    A copy of steps with the step called name swapped for replacement. Throws on an unknown name.

  • stepfunction

    Build a PhaseStep.

  • zvukPortfunction

    A ReelAudioPort over a zvuk engine. A name loaded with loadVariants plays its next take; one loaded with loadSound plays as is. A name that is not loaded is…

  • ReelAudioPortinterface

    The audio engine as the cues see it.

  • What a symbol is told about where it landed. Handed to ReelSymbol.onReelLanded(ctx) by the engine on every landing path, so a symbol can decide what its…

  • StepContextinterface

    What every step of a phase receives. The reel and the numbers a step needs, plus two ways to wait that a slam can cut: wait for time, until for a condition…

  • StopStepsinterface

    The steps PhaseProfiles.stop configures. Merge into it for a step you insert.

  • The AnticipationStepContext type alias in the pixi-reels API.

  • Timing and animation profile for a speed mode.

  • The StartStepContext type alias in the pixi-reels API.

  • The StopStepContext type alias in the pixi-reels API.

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

Questions

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

How do I stagger reel starts so they begin one after another?open

The active SpeedProfile's spinDelay staggers reel starts; tune it per profile via .speed(name, { ..., spinDelay }).

Question page
How do I add a turbo (fast-spin) mode?open

Register a faster profile (.speed('turbo', SpeedPresets.TURBO)) and switch with reelSet.setSpeed('turbo').

Question page
How do I boost only the current spin without changing the speed profile?open

There is no boost-only call. skipSpin() slams the current drop, and as a round-scoped side effect switches the active profile to the fastest registered one and emits skip:boosted. That speed change only affects subsequent spins, mid-spin speed switching is not supported, and the next spin() restores your original profile. For a slam with no speed side effect, use slamStop().

Question page
How do I control the bounce/overshoot when a reel lands?open

Tune bounceDistance and bounceDuration on the SpeedProfile.

Question page
How do I make a reel land with a bounce?open

The stop phase bounces by bounceDistance / bounceDuration on the active SpeedProfile.

Question page
How do I keep the win highlight in sync with the win sound?open

Both fire from the same win:group event. Start the sound in the same listener that triggers the highlight.

Question page
How do I settle the wheel pointer with a believable bounce?open

Tween the wheel rotation with a GSAP back.out ease to settle the pointer, game-layer.

Question page
How do I rise the anticipation music as tension builds?open

Start or raise it when you call setAnticipation; drive the layers from your audio engine.

Question page
How do I duck the music during a big-win count-up?open

Duck the music in your audio layer when the win roll-up starts (e.g. on win:start).

Question page
How do I pitch the count-up sound higher the longer it runs?open

Ramp the playbackRate of the count-up sound in your audio code as the total climbs.

Question page
How do I fire haptics/vibration on a jackpot hit?open

Fire navigator.vibrate(...) in your coin:locked / board:full handler.

Question page
How do I cut all feature sounds cleanly when the player exits?open

Stop your audio in the same teardown that hides the feature / calls board.destroy().

Question page