# Symbol classes

> Pick or write the class that draws a symbol, from sprites to Spine, and animate it when it wins.

Source: https://pixi-reels.schmooky.dev/mechanics/symbols/

A symbol is what fills one cell. Three classes ship with the library, and
the abstract base class is there for your own.

| Class | Use it for |
|---|---|
| `SpriteSymbol` | Static images. One texture per id. |
| `AnimatedSpriteSymbol` | Sprite-sheet animation loops. |
| `SpineSymbol` | Skeletal animation via `@esotericsoftware/spine-pixi-v8`. |
| `ReelSymbol` (abstract) | Your own drawing. |

## Register

The builder's `symbols()` call hands you a registry. You register a class
with its options, not an instance. The engine constructs the symbols and
pools them.

```ts
builder.symbols((r) => {
  r.register('cherry', SpriteSymbol, { textures: { cherry: cherryTex } });
  r.register('bar',    AnimatedSpriteSymbol, { frames: barFrames, animationSpeed: 1.5 });
});
```

## Custom symbol

Extend `ReelSymbol`. A symbol is activated with an id, may then get
`playWin` or `stopAnimation`, and is deactivated when the pool takes it back.

`resize(width, height)` runs on every swap, so positioning belongs there and
not in the constructor. A symbol that positions itself in the constructor
ends up in the wrong place after the first swap.

```ts
import { ReelSymbol } from 'pixi-reels';
import { Graphics } from 'pixi.js';

export class BlockSymbol extends ReelSymbol {
  private _g = new Graphics();

  constructor(opts: { colors: Record<string, number> }) {
    super();
    this.view.addChild(this._g);
    (this as any)._opts = opts;
  }

  protected onActivate(symbolId: string): void {
    const color = (this as any)._opts.colors[symbolId] ?? 0x888888;
    this._g.clear().roundRect(0, 0, 140, 140, 10).fill(color);
  }

  protected onDeactivate(): void {
    this._g.clear();
  }

  async playWin(): Promise<void> {
    // pulse for 400ms
    this.view.scale.set(1.1);
    await new Promise((r) => setTimeout(r, 400));
    this.view.scale.set(1);
  }

  stopAnimation(): void { this.view.scale.set(1); }
  resize(w: number, h: number): void { this._g.clear().roundRect(0, 0, w, h, 10).fill(0x333333); }
}

// Register:
builder.symbols((r) => {
  r.register('red',   BlockSymbol, { colors: { red: 0xff6d70 } });
  r.register('blue',  BlockSymbol, { colors: { blue: 0x4cc2ff } });
});
```

## Weights

A symbol with no weight gets 10. Change it with `weights()` on the builder.

```ts
builder.weights({ cherry: 40, bar: 20, seven: 4 });
```

A bigger number comes up more often. Weights only affect the random fill,
which is the strip while it spins and the buffer cells. A grid from
`setResult()` ignores weights, because the server decides what lands.

`weights()` is one table for the whole set. To keep a symbol out of the
buffer cells, or to make one reel draw differently, add a pool on top:

```ts
builder.randomSymbols({ exclude: ['EMPTY'] });                     // every reel
builder.randomSymbols({ exclude: ['COIN'] }, { slots: 'buffer' }); // buffers only
builder.randomSymbols({ weights: { WILD: 40 } }, { reel: 2 });     // reel 2 only
```

The same pools are available at run time through `reelSet.randomSymbols`,
which is where a game-mode switch belongs. [Buffer indexing](/mechanics/big-symbols/#concept-buffer-indexing)
has the layering rules.

## Headless testing

`HeadlessSymbol` draws nothing and needs no textures or canvas. Use it in
tests.

```ts
import { HeadlessSymbol } from 'pixi-reels/testing';

builder.symbols((r) => {
  r.register('a', HeadlessSymbol, {});
  r.register('b', HeadlessSymbol, {});
});
```

[Cheats & testing](/learn/cheats-and-testing/) has the full setup.

## Demos

Production art comes first, then what you can do to a symbol after it lands. Placeholder classes and symbols for sideways sets are at the end. Art that overflows its cell is on [Layers](/mechanics/layers/). The blurred copies a reel shows while it spins are on [Spinning art](/mechanics/spinning-art/).

## Production art

### Sprites from an atlas

Sprite symbols loaded from one TexturePacker atlas, so every frame comes from one file and one texture upload. Each id is registered with `BlurSpriteSymbol` from `@pixi-reels/kit`, which shows the atlas's blur frame while the reel spins.

Live demo (texture-atlas-symbols): https://pixi-reels.schmooky.dev/mechanics/symbols/#texture-atlas-symbols

### Spine skins

Each symbol tier is one Spine skeleton, and each id in the tier is a skin of it. The board is a gapless 3-4-4-4-4-3 grid. The skeletons are wrapped in `StaticSpinSymbol`, so the reels spin on blurred snapshots and no skeleton runs mid-spin.

Live demo (spine-skins-3-4-4-4-4-3): https://pixi-reels.schmooky.dev/mechanics/symbols/#multi-skin-spine-tiers-on-a-compact-grid

## After the reels land

### Your own win animation

`WinPresenter` takes a `symbolAnim` callback that runs instead of `playWin()`. It gets the symbol, its cell and the win, so the animation can differ per `win.id`. Here the top line bounces harder than the other two.

Live demo (paylines-custom-animation): https://pixi-reels.schmooky.dev/mechanics/symbols/#custom-per-symbol-animation

### Transform a symbol

A low symbol turns into a higher one after the reels stop. `reelSet.setSymbolAt(reel, cell, id)` swaps the one cell and leaves the rest of the reel alone. Call it after `spin:complete` or `spin:reelLanded`: it throws while the reel is spinning and on a big symbol's anchor.

Live demo (symbol-transform): https://pixi-reels.schmooky.dev/mechanics/symbols/#symbol-transform

## Blank cells

`EmptySymbol` takes a slot on the strip and draws nothing. Register it under an id such as `'empty'` and weight it heavily, and most cells land blank. Hold & Win boards use it for the empty cells between coins.

Live demo (empty-symbol): https://pixi-reels.schmooky.dev/mechanics/symbols/#emptysymbol-render-nothing-for-a-registered-id

## Prototype symbols

### Cards without art

`CardSymbol` draws a coloured card with a label using `Graphics`, so it needs no assets and stays sharp at any cell size. The package exports it with a ready deck: `import { CardSymbol, CARD_DECK, WILD_CARD } from 'pixi-reels'`. Use it for prototypes and tests, and ship `SpriteSymbol`, `AnimatedSpriteSymbol` or `SpineSymbol` in the game.

Live demo (card-symbol-debug): https://pixi-reels.schmooky.dev/mechanics/symbols/#cardsymbol-debug--prototyping-helper

### Phase colours

`PhaseCardSymbol` is a `CardSymbol` that is grey at rest and takes the colour of the phase its reel is in: sky for `start`, blue for `spin`, amber for `anticipation`, violet for `stop`, and green for a moment after landing. Use it to check phase timing by eye.

Register it like any symbol, then call `PhaseCardSymbol.watch(reelSet.reels)`. The watcher colours every card from the reels' `phase:enter`, `landed` and `symbol:created` events, custom phases included, and returns a function that stops it. A card does not know its reel, so without the watcher it stays grey. `setPhase()` is public if something else knows the phase. `colors` overrides or extends `PHASE_CARD_COLORS`, and a phase with no entry uses `other`.

Live demo (phase-colors): https://pixi-reels.schmooky.dev/mechanics/symbols/#phasecardsymbol-read-the-phase-off-the-board

## Sideways sets

### Writing a symbol class

A hand-written `ReelSymbol` on a horizontal set with wide cells. The class has no orientation code. `resize(width, height)` is in screen pixels whichever way the strip travels, so the plate's marker and glyph stay upright while the strip scrolls along x. The engine never rotates a symbol container, so third-party symbol classes work unchanged.

A symbol can read `this.mainAxis` (`'y'` vertical, `'x'` horizontal) for effects that follow travel, such as motion blur. Do not use it for layout.

Live demo (symbols-horizontal-resize): https://pixi-reels.schmooky.dev/mechanics/symbols/#authoring-a-symbol-for-a-sideways-set

### One registration for both axes

Four reels of three cells, built once vertical and once horizontal, landing the same grid. Both sets use the same symbol registration. The builds differ only in `symbolSize`, whose two numbers swap, because a horizontal board is the vertical one transposed.

Live demo (symbols-transposed-pair): https://pixi-reels.schmooky.dev/mechanics/symbols/#the-same-symbols-on-both-axes
