pixi-reels

Step-by-step

Your first reelset

This page builds a 5x3 fruit slot from nothing.

0. Before you start#

You have a Pixi app already. Install the engine with npm i pixi-reels.

1. Make a builder#

import { ReelSetBuilder } from 'pixi-reels';
const builder = new ReelSetBuilder();

You configure the builder, then build the reel set from it at the end.

2. Set the grid#

builder
  .reels(5)
  .visibleCells(3)
  .symbolSize(140, 140)
  .symbolGap(4, 4)           // optional
  .bufferSymbols(1);         // optional, default 1

Nothing is on screen yet. The builder does nothing until you call .build().

3. Register symbols#

Every symbol needs an id and a class. Three classes ship with the engine.

  • SpriteSymbol draws one static texture
  • AnimatedSpriteSymbol plays a sprite-sheet animation
  • SpineSymbol plays a Spine skeleton

For anything else, extend ReelSymbol and draw what you like.

import { SpriteSymbol } from 'pixi-reels';

builder.symbols((r) => {
  r.register('cherry', SpriteSymbol, { textures: { cherry: cherryTex } });
  r.register('seven',  SpriteSymbol, { textures: { seven: sevenTex } });
  r.register('wild',   SpriteSymbol, { textures: { wild: wildTex } });
});

If you register nothing, .build() throws with symbols() must register at least one symbol.

4. Weights, ticker, build#

app is your Pixi app.

builder
  .weights({ cherry: 40, seven: 8, wild: 5 })
  .ticker(app.ticker);

const reelSet = builder.build();
app.stage.addChild(reelSet);

You now see a 5x3 grid of random symbols, standing still.

Real slots do not open on random symbols. They open on a chosen frame, or on whatever the player left behind last round. Set that with initialFrame.

builder.initialFrame([
  { visible: ['cherry', 'seven', 'cherry'] },
  { visible: ['wild', 'cherry', 'seven'] },
  { visible: ['seven', 'seven', 'cherry'] },
  { visible: ['cherry', 'wild', 'cherry'] },
  { visible: ['seven', 'cherry', 'cherry'] },
])

It takes buffer symbols too, if you want something peeking in from off-window.

5. Spin#

const promise = reelSet.spin();

The reels spin and keep spinning.

Do not call this straight from a button click. Call it from the state that opens a round and sends the server request. The button starts a round, and the round starts the reels.

6. Stop#

The spin promise does not resolve on its own. It waits until you say what to land on.

const promise = reelSet.spin();

reelSet.setResult([
  { visible: ['wild','seven','wild'] },
  { visible: ['seven','wild','seven'] },
  { visible: ['wild','seven','wild'] },
  { visible: ['seven','wild','seven'] },
  { visible: ['wild','seven','wild'] },
]);

await promise;

The reels stop and show your grid.

The classic mistake is await reelSet.spin() on its own. It never resolves, because nothing told it where to stop. Hold the promise, set the result, then await.

What next#