pixi-reels
All mechanics

Mechanics

Reel windows

Show the reels through a rounded window, a card per reel or any shape you draw.

Demos

Each demo passes a mask strategy to .maskStrategy(...). Rounded windows come first, then the helpers that trim or combine a mask, then a mask drawn from your own path.

Rounded corners#

The whole window#

RoundedRectMaskStrategy with scope: 'set' rounds the corners of the box around all the reels. It works at any cross gap, which is why it is the default scope.

Loading recipe…

Each reel as a card#

scope: 'reel' rounds every reel’s box instead, so the reels read as separate cards.

It needs a cross gap above 0. At gap 0 neighbouring reels share an edge, and rounding both sides of it cuts a notch into every seam. The strategy warns once when it sees touching reels.

Loading recipe…

Outer corners only#

scope: 'outer' keeps one rect per reel, as the default mask does, so buffer cells past a short reel stay hidden. It rounds a corner only where it is also a corner of the box around all the reels: the outer pair on the first reel and on the last. The inner edges stay square, so it works at cross gap 0, where scope: 'reel' notches. corners: { topLeft: true, ... } limits any scope to the named screen corners.

On a jagged set the corners of the box may not touch any reel, and then nothing is rounded. Use SilhouetteMaskStrategy there.

Loading recipe…

Jagged boards#

A pyramid has no single rectangle to round. Rounding each reel notches the seams, and rounding the bounding box hides the staircase and shows buffer cells past the short reels. SilhouetteMaskStrategy follows the outline of all the reels together and rounds every corner of it. The inward corners, where a short reel meets a taller one, use concaveRadius. On a board with no steps it gives a plain rounded rect.

The reels must touch, at cross gap 0. With a gap the strategy warns and falls back to a rounded rect per reel.

Loading recipe…

Hold & Win cells#

Every Hold & Win cell is its own 1x1 reel set with its own mask. cellMask on the Hold & Win builder takes a function that is called once per cell with { reel, cell } (column and row) and { cols, rows, corners }, and returns that cell’s strategy. Here every cell gets a plain rect except the four corner cells, which each round their one outer corner, so the gapless board clips as one rounded window made of fifteen masks. corners is the cell’s corner set already worked out, for the short form (_, { corners }) => new RoundedRectMaskStrategy({ radius, corners }).

Loading recipe…

Trimming and combining#

Inset and compose#

inset(strategy, px) shrinks what any strategy draws by px on every side, and a negative value grows it. Use it when the art shows a pixel past the frame. composeMasks(a, b, ...) joins several strategies into the viewport’s one mask. Here a rounded window inset by 4px is joined with a banner strip above the reels.

composeMasks can only form a union, because a Graphics mask is the union of its filled shapes. To subtract, use .cut() inside a PathMaskStrategy.

Loading recipe…

A different trim per side#

Frame art rarely has four equal lips. inset(strategy, { top, right, bottom, left }) trims each side by its own amount, for example inset(new RoundedRectMaskStrategy({ radius: 43 }), { top: 4, bottom: 12 }). Sides are screen sides in every orientation, and a side you leave out is not trimmed. Here the bottom lip is four times thicker than the top one.

Loading recipe…

Any shape#

PathMaskStrategy takes a (graphics, context) => void callback. The context carries rects, width, height, axis and bleed. Do not call g.clear(), because the strategy already has. The demo fills the board and cuts a hole in the middle, so only the outer ring of symbols shows.

cut() subtracts from the last shape filled, so fill first. If you draw the hole before filling, the mask is empty and the board disappears, with no error.

Loading recipe…

Concept

The viewport clips the reels through a MaskStrategy, so buffer cells never show past the grid. The default is RectMaskStrategy, and the strategies below are options you add on top.

BoardStrategy
Square frame artRectMaskStrategy (default)
Rounded frame, reels flushRoundedRectMaskStrategy (scope: 'set')
Reels as separate cards, with a cross gapRoundedRectMaskStrategy (scope: 'reel')
Rounded frame, one rect per reel, any gapRoundedRectMaskStrategy (scope: 'outer')
Hold & Win board, a mask per cellcellMask((cell, { corners }) => ...)
Pyramid or MultiWays, rounded, reels flushSilhouetteMaskStrategy
Hexes, holes, cut-outsPathMaskStrategy

inset(strategy, px) shrinks any of them by a margin, and composeMasks(a, b, ...) joins several, your own strategies included.

Writing your own#

Implement build(ctx) and update(g, ctx), set version = MASK_STRATEGY_VERSION, and pass it to .maskStrategy(...). Try PathMaskStrategy first. A class is only worth it when it keeps state between draws.

Two things to respect. ctx.axis matters because rects are in screen space in every orientation (axis.toLocal(w, h) gives { cross, main }). ctx.bleed inflates the cross axis only. Add the optional draw(g, ctx) and your strategy composes like the built-in ones.

API

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

  • Fluent builder for HoldAndWinBoard.

  • Any mask you can draw, without the class.

  • v1 default: a per-reel rectangular mask. Each reel is clipped to its own (mainOffset, extent) box so pyramid shapes clip cleanly without buffer-cell peek…

  • The configurator you call before every reel set.

  • Rounded-corner rectangles, per reel or per set.

  • Rounds the OUTLINE of the whole reel set, staircase and all.

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

  • composeMasksfunction

    Union several strategies into one mask.

  • insetfunction

    Shrink (or grow) any strategy's mask by a number of pixels - one number for all four sides, or { top, right, bottom, left } for a different trim per screen…

  • stepfunction

    Build a PhaseStep.

  • MaskContextinterface

    Everything a mask strategy is given. Passed as one object so the axis cannot be forgotten, and so later additions do not break the signature.

  • MaskStrategyinterface

    Strategy for building the viewport's clip mask. Public. pass a custom implementation to ReelSetBuilder.maskStrategy(...) to clip the reels with any shape…

  • Wininterface

    One "win" as the presenter sees it: an ordered set of cells to highlight.

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

  • Version marker every strategy must carry. A v1 strategy has positional (rects, totalWidth, totalHeight) parameters and no axis; handed a MaskContext it would…

  • 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 share one mask across many cells?open

maskStrategy(new SharedRectMaskStrategy()) clips many cells with a single mask.

Question page