pixi-reels
Reference
Scene graph

Viewport and masks

The five layers under and above the mask, and the strategies that draw the mask.

The player sees three rows, but every reel is longer than that. The extra symbols parked above and below the window, the buffer cells, are real PixiJS objects with real positions, and something has to hide them or the board looks like a tall list. The obvious tool is a mask: a stencil shape, and PixiJS only draws what falls inside it. The trouble starts as soon as the game needs something to escape that stencil. A winning symbol wants to pop out over the frame art. A big win needs the losers darkened while the winners stay bright. A sticky symbol flying from one cell to another has to cross over the reels in between. One mask around everything would clip all of that.

So the viewport is not one container with a mask but a short stack of them: one masked layer that holds the reels, and four more layers above the mask for the things that must break out of it. The ReelViewport is that stack. The ReelSet owns it, it is the ReelSet's only display child, and each reel keeps a reference to it so it can add its own container to the masked layer. This page walks the layers from the bottom up, then every shape the mask can take.

The layer stack

Figure 1 draws the viewport's five children in child order, bottom to top. In PixiJS a later child renders on top of an earlier one, so reading upwards is reading towards the player. Look for the mask: it is a single Graphics inside the lowest layer, applied to that layer as a whole, and nothing above it is clipped by it. Everything that must escape the clip lives in one of the four layers above.

later child, drawn on toppromotedLayerRenderLayer; promote() attaches a view here without reparenting itspotlightContainerwinning views are reparented here during show()dimOverlaya black rect of viewport size, alpha 0.5; hidden until showDim()unmaskedContainerabove the mask, same local spaceunmask symbolsat rest onlypin overlayszIndex 10000, in motionmovePin flightsthe travelling symbolmaskedContainer.mask = the Graphics, itself a childmaskGraphicsReel 0zIndex 0Reel 1zIndex 1Reel 2zIndex 2Reel 3zIndex 3Reel 4zIndex 4
The viewport's five children in child order, drawn bottom to top. A later child renders on top, so the promoted layer beats an active spotlight and the dim overlay never darkens a winner.

From the bottom. The masked container holds every reel and the one mask that clips them all. Each reel's container has a draw order equal to its index, positive when reels stack ascending and negative when they stack descending, which decides whether the last reel draws in front of or behind its neighbour. In warp curve mode a ReelWarp stands in for the reel container and copies that order.

The unmasked container sits directly above the mask in the same coordinate space, so anything moved into it keeps its position but stops being clipped. Three things live here. Symbols registered with unmask: true are lifted here while the reel is at rest, so a tall or wide piece of art can overhang its cell and even cross into a neighbouring reel. Pin overlays, the symbols the engine draws over cells that stay put across spins, sit here while they are in motion, at a very high draw order. And when a pin is moved from one cell to another, the travelling symbol flies through this layer.

The dim overlay is a black rectangle the size of the viewport, hidden until something asks for it. When shown it darkens the two layers below it, reels and unmasked symbols, and nothing above it. The spotlight container is where winning symbols are moved during a win presentation; because it is above the dim, winners stay bright while everything else goes dark. The promoted layer is the last child and so draws above everything, even an active spotlight. It is a PixiJS RenderLayer rather than a container: a view attached to it keeps its real parent and only changes where it renders, sorted by whatever draw order the symbol already carries.

promotedLayerrender order only; a view keeps its parent
Containersordinary children, sortable
dimOverlayhidden until a dim request

The viewport can be constructed on its own, and then its defaults are a position of {0, 0}, a plain RectMaskStrategy, the vertical-forward axis and a bleed of 0. The builder never relies on those: it passes its own axis, the strategy it chose, and, in warp mode only, the curve bleed. One note if you read the source: the class comment says "three stacking layers" and lists four, but there are five children. The code is the source of truth here.

One mask, per-reel geometry

There is exactly one mask Graphics per viewport, and it applies to the masked container as a whole. Masks are never applied to individual reel containers. When this page says "per-reel masking", it means drawing one rectangle per reel into that single Graphics. A PixiJS mask is the union of every filled shape it contains, so the default strategy gets a jagged but rectangular clip, one that follows a pyramid layout exactly, with no shader and no extra draw calls.

The thing that draws those shapes is a mask strategy: a small object with a build() that creates the Graphics and an update() that redraws it. Both receive a MaskContext describing the current board, and the table lists what is in it.

FieldMeaning
rectsone ReelMaskRect per reel, screen space, viewport-local, in reel order; empty before the builder supplies them
width, heightthe viewport box
axisthe set axis, so a strategy can tell main from cross
bleedcross-axis curve bleed; 0 unless warp mode with curveBleed
originoptional; set only by inset(), shifts where the box starts

The full contract is interface MaskStrategy { readonly version: 2; build(ctx): Graphics; update(g, ctx): void }. A second, smaller interface exists for strategies that want to be combined: a DrawableMaskStrategy adds draw(g, ctx), which draws into a Graphics somebody else owns and so must never call clear(). That is what lets several strategies draw into one mask. All fills are white; the colour is never rendered, because a mask is a stencil, not a picture.

Every strategy

Figure 2 draws the same small pyramid set eight times, once per strategy. The grey strips are the full reels, buffer cells included; the shaded shape is what the mask lets through. Compare the first two panels: the per-reel rectangles hug each reel, while the shared rectangle lets the buffer cells of the short outer reels show through. Then look at the last two, which are not shapes of their own but ways of changing or combining the others.

Rectone rect per reelSharedRectone bounding boxRounded 'set'one rounded union boxRounded 'reel'each reel roundedRounded 'outer'union corners onlySilhouettestaircase outlinePathfill() then cut()inset + composeinset(s, 8) + banner
The same pyramid set (3, 4, 5, 4, 3 cells, one buffer cell per side) under each strategy. The shaded shape is what the mask lets through; the grey strips are the full reels, buffer cells included. The table below has every rule and caveat.

In words: Rect is the default and draws one rectangle per reel. SharedRect draws one box around the whole set, which is what you need when a symbol spans the gap between reels or leans out of its column. RoundedRect rounds corners, and its scope decides which corners: the whole set, each reel, or only the outer corners of the union. Silhouette traces the staircase outline of a pyramid so the rounding follows the steps. Path hands you the Graphics and lets you draw anything, including holes. inset shrinks or grows another strategy by a margin, and composeMasks unions several strategies into one mask, for a board with a detached banner or side cell. The table has the exact rules and every caveat.

StrategyDrawsRules and caveats
RectMaskStrategyone rect per ctx.rects entry, each inflated on the cross axis by bleed on both sides; with no rects, a single viewport-sized rectthe default. No buffer peek past short reels. With a cross gap, a block spanning reels is clipped in the gap.
SharedRectMaskStrategyone bounding rect from origin to width x height, bleed-inflated on the cross axisfor blocks across a gap, unmask symbols and curve lean. On pyramids it shows buffer cells past short reels (the pyramid peek, usually behind frame art). bleed ?? 0 guards third-party contexts, otherwise the rect is NaN and clips everything.
RoundedRectMaskStrategy { radius, scope = 'set', corners }'set': one rounded union box. 'reel': every reel rect rounded on its own. 'outer': per-reel rects where a corner rounds only if it coincides with a union-box corner (CORNER_EPS 0.5 px)throws on a negative or non-finite radius or a non-object corners. 'reel' at gap 0 warns once (mask-rounded-touching) because the seams notch; it warns rather than throws because a MultiWays reshape can legally pass through a touching layout. 'outer' may round nothing on a jagged set. Hold & Win uses corners per cell.
SilhouetteMaskStrategy { radius, concaveRadius = radius }the rectilinear union outline of the reel rects: leading main edge in cross order, then the trailing edge back; convex corners get radius, concave corners get concaveRadiusneeds a zero cross gap. Disjoint reels warn once (mask-silhouette-disjoint) and fall back to RoundedRect scope reel. Duplicate and collinear vertices are dropped (RING_EPS 0.5), so a uniform set yields four corners. Bleed applies only to the two outermost cross edges, with !== 0 so a negative bleed from inset() still applies. Under 3 ring points: a plain rect.
PathMaskStrategy(fn)whatever (g, ctx) => void draws; clear() is already handledthrows if the argument is not a function. cut() subtracts from the last filled shape, so fill first and cut second or the mask is empty and the board invisible.
inset(strategy, px | { top, right, bottom, left })the wrapped strategy, shrunk (positive) or grown (negative); sides are screen sides in every orientationcross-axis inset goes through a negated bleed plus an origin shift; main-axis inset shrinks rect sizes and the box and shifts origin. Mixing the two forms double-counts. A custom strategy that ignores ctx.origin insets in size but not position. Throws inset(): expected a finite number... on bad input.
composeMasks(...strategies)the union of every member; drawable members share one Graphics, others get a nested child Graphics cached per host in a WeakMapunion only; PixiJS cannot intersect or subtract across strategies. Throws on an empty list. The motivating case is a reel set plus a detached banner or side cell.

Every strategy and combinator is exported from the package entry, along with MASK_STRATEGY_VERSION, isDrawableMaskStrategy and the types ReelMaskRect, MaskStrategy, MaskContext, DrawableMaskStrategy, MaskCorners, MaskPathFn, RoundedMaskScope, RoundedRectMaskOptions, SilhouetteMaskOptions and InsetSides. The one helper that is not re-exported from index.ts is bleedOutset. Worked examples are in the masks recipes.

Which strategy you get without asking

Most games never choose a mask. The builder picks one, and it only ever picks between the first two: the per-reel rectangle by default, or the shared rectangle when something would otherwise be clipped. If you called .maskStrategy() yourself, that choice always wins and the rules below are skipped.

The first rule looks at your symbols. If any registered symbol is wider than one reel (size.reels greater than 1) or is allowed to escape the mask (unmask: true), and there is a gap between reels, the set gets the shared rectangle. Without a gap there is nothing to clip, so the rule stays quiet; a tall stack within one reel never crosses a column edge, so it does not trigger it either. The second rule looks at curvature. If the curve focus is anything but 'reel' and a curve is set, the set gets the shared rectangle too, gap or no gap, because a set-focused curve leans cells out of their own column regardless. Both rules log an info notice named mask-auto-shared saying which reason fired. Otherwise you get the default. The decision is drawn on the builder page.

There is also a runtime check for the shared rectangle's one weakness. When reels change height after build, through setColumn and its relatives, the set warns once (shared-mask-jagged) if the mask now covers buffer cells past a short reel. It finds out honestly: it hit-tests the mask Graphics with containsPoint just past each short reel's ends, rather than guessing from the strategy's name.

The per-reel rects

The rectangles a strategy receives are computed by the builder once the reels exist. Each one is positioned by marching across the reels on the cross axis, and by the reel's own offset inside the tallest strip on the main axis, according to the anchor you chose (start, centre or end). Its size is one cell across and the reel's full extent along.

position = setAxis.toScreen(reelIndex * (crossCell + crossGap), mainOffsetFor(extent, tallest))
size     = setAxis.toScreen(crossCell, extent)

mainOffsetFor: 'start' -> 0   'end' -> tallest - extent   'center' -> (tallest - extent) / 2

The viewport takes those rectangles through one method, updateMaskSize(width, height, rects = []). It stores the three values, asks the strategy to redraw, and resizes the dim overlay to match, so a spotlight never dims a stale rectangle. It is called from three places: the builder, right after the reel loop; every board change on the set, because addReels, removeReels, addRows, removeRows, setColumn, splitSymbol, resetColumns and expand all go through ReelSet._afterBoardChange(); and MultiWays reshapes. Before the first call the viewport has no rects, so the mask draws its bounding-box fallback. The current values are readable through maskWidth, maskHeight, maskRects, maskGraphics (used by debug code and by the jagged check above), axis and isDestroyed.

The dim reference count

Two different features darken the board: the win spotlight, and destroySymbols({ dim: true }), which dims while symbols are removed. They can overlap, and if each simply switched the overlay on and off, the first one to finish would switch it off under the other. So the overlay is reference counted. Figure 3 follows one such overlap; notice that the overlay only hides when the count returns to zero, and that each show sets the alpha, so the latest request decides how dark.

count 0hiddencount 1visible, alpha 0.5count 2visible, alpha 0.35count 1still visiblecount 0hidden againspotlight: showDim(0.5)destroySymbols: showDim(0.35)hideDim()hideDim()
Two users of the dim overlay overlap. Neither can hide the other's dim, because the overlay only hides when the count returns to zero.

In code, showDim(alpha = 0.5) increments the count, sets the overlay's alpha and makes it visible; hideDim() decrements and hides only when the count reaches zero. The spotlight asks for 0.5 and destroySymbols for 0.35. From reading the code: the Graphics fill itself is drawn at alpha 0.5, and showDim sets the container alpha on top of that, so the effective darkness is 0.5 x alpha, not the number you passed.

Warp mode skips the unmasked layer

Warp mode draws a curved reel by rendering the reel to a texture and bending the texture. Only what is inside the reel container ends up in that texture, so anything the engine lifts out of the container is drawn flat: symbols registered with unmask: true, the spotlight and the pin overlays all sit flat over a curved board. When warp mode, a curve and an unmask symbol are combined, build() logs the info notice warp-skips-unmask and suggests curveMode('symbol'), which bends each symbol individually and so keeps lifted ones on the drum. See curvature.

Destroy

ReelViewport.destroy() first detaches every view from the promoted layer, so a pooled symbol that outlives the viewport is not left holding a reference to a dead render layer, and then destroys itself and its children. The ReelSet calls it after the symbol pool and before clearing pins; the full order is on the classes page.