pixi-reels
Reference
Drum

Curvature

How a flat strip is projected onto a drum, in two modes.

A real slot reel is a cylinder. The cell facing you is full size; the ones above and below have rotated away, so their far edges sit further from your eye, and a camera draws them as trapezoids rather than as smaller rectangles. Flat 2D reels are fine for many games, but when a design calls for that mechanical drum look, every symbol on the reel has to be squashed and keystoned by exactly the right amount, and it has to stay that way while the strip scrolls past at thirty cells a second.

pixi-reels fakes the drum with one small model per reel, packages/pixi-reels/src/core/ReelCurve.ts, that is a pure function: give it a flat coordinate along the strip and it tells you where that point lands on the drum and how much it has shrunk. The motion layer keeps laying the strip out flat and knows nothing about curvature. The curve is then drawn in one of two ways: per symbol, by handing each one a four-cornered shape to fit itself into, or per reel, by rendering the whole reel to a texture and bending that. This page covers the model, the rule that keeps it from corrupting the motion layer, the two renderers and where the "camera" sits.

The drum

Figure 1 is the model from the side. On the left is the flat strip the motion layer produces, three visible cells and a buffer at each end. In the middle is the cylinder, seen edge-on, with the camera off to the left; the window's half extent is wrapped onto the arc, so the middle of the window is the point of the drum nearest the camera. On the right is what the player sees. Notice two things: the middle cell is drawn exactly 1:1, and the edge cells are both shorter along the strip and narrower at their far edge, which is the keystone shape a cylinder really produces.

flat stripbufABCbufside viewcameraphi = 0phi = -arcr = halfExtent / arcwhat you seeABC
Side view. The window's half extent is wrapped onto a cylinder; the middle cell (phi = 0) is drawn 1:1 and everything else is pushed through a perspective divide that shrinks it by how far it has receded. On the right, the keystone you see: far edges narrower, edge cells shorter along the strip; the buffers past the window continue on a straight line.
visible cellprojected inside the window
buffer cellfills the band the drum leaves short of the window edge
ReelCurvepure projection, no positions written
rendererPerspectiveCell or ReelWarp

The model has two knobs, both set through the builder. amount, from 0 to 1, says how much of the drum you see: at 1 each half of the window wraps through one radian, about 57 degrees, so the window spans nearly a third of the cylinder. depth says how much a cell at the very edge of the window has shrunk compared with the middle one, as a fraction; a depth of 0.5 means the edge cell is drawn at two thirds of its true size. Everything else is derived from those two and the reel's geometry. Here is the derivation in words, with the table below giving each step its formula.

First, measure the window. Its length along the strip is the visible cell count times the pitch, minus one trailing gap, because the gap after the last cell is not part of the window; half of that is the half extent. Then decide how far round the drum that half window should wrap, which is the arc, simply amount times one radian. Those two fix the drum's radius: an arc of length halfExtent subtending arc radians has radius halfExtent / arc. That means any flat coordinate can be turned into an angle, phi: how far it is from the middle of the window, divided by the radius. The middle cell is at phi 0, the window edges are at plus and minus arc, and the buffer cells are beyond that.

Next, the shrinking. A point on a cylinder that has turned away by an angle phi is 1 - cos(phi) radii further from the camera than the front, so the natural perspective shrink is one over one plus some constant times that distance. The constant, k, is chosen so that the shrink at the window edge is exactly what you asked for: solving 1 / (1 + k(1 - cos arc)) = 1 / (1 + depth) for k gives depth / (1 - cos arc). That is why depth is defined as "the shrink at the edge": it is the one number a designer can see and judge.

Finally, the position. Seen from the front, a point at angle phi on a cylinder sits sin(phi) radii from the centre line; multiply by the perspective scale and you have where it lands. The result is then normalised so that the middle cell is drawn exactly 1:1. The alternative, stretching the mapping so the window edges land on the window edges, would stretch the middle row along the strip but not across it, which reads as a squashed centre. The consequence of keeping the centre honest is that the drum's ends fall a little short of the window edges, and the buffer cells fill that band; which is why the figure's caption says the buffers "continue on a straight line".

QuantityFormulaMeaning
halfExtent(visibleCells * pitch - (pitch - cellMain)) / 2half the length of the window along the strip
arcamount * MAX_ARC, with MAX_ARC = 1.0 radhow far round the drum each half of the window wraps
rhalfExtent / arcthe drum radius that makes the half window wrap through exactly arc
phi(main - halfExtent) / ra flat coordinate as an angle: 0 at the middle, +-arc at the window edges
kdepth / (1 - cos arc)the perspective strength that makes the window edge shrink by exactly depth
scale(phi)1 / (1 + k * (1 - cos phi))1 at the middle, 1 / (1 + depth) at the window edge
main(phi)halfExtent + halfExtent * sin(phi) * scale(phi) / arcthe projected position inside the window; a straight line past it

Past the window edge the position continues as a straight line from where the edge actually landed, using the slope the curve had there (_edgeSlope), while the scale keeps following 1 - cos(phi). That keeps a buffer cell from being a flat rectangle sitting next to a hard-curved neighbour.

In code, the config is ReelCurveConfig, { amount, depth? }. builder.curve(0.35) and curve({ amount: 0.35 }) mean the same thing, and curvePerReel([...]) sets one per reel. resolveCurveConfig clamps amount to 0..1, defaults depth to amount * 0.5, and caps depth below 0.9 * cos(arc). The cap is not cosmetic: past cos(arc) the projection stops being monotonic and the cells at the window edge fold back over each other. An arc below 1e-4 reports isFlat, and the builder then does not create a curve object at all, which keeps a flat set byte-identical to an uncurved build.

The model is bound to real pixel sizes by setGeometry(cellMain, cellCross, pitch, visibleCells). Reel.setCurve derives cellMain from the pitch the reel is actually spinning on minus the gap, so a MultiWays reel is measured on its spinning strip, and Reel.reshape re-binds it after a reshape. The main entry point for a renderer is quadFor(mainStart, inset), which projects the rectangle the art really occupies rather than the whole cell. For a trimmed atlas frame the cellInset (from textureCellInset) is much smaller than the cell, and projecting the whole cell would inflate the symbol and give it the cell's keystone instead of its own, milder one. The quad comes back view-local, clockwise from the screen's top-left, so art stays upright on a horizontal set. mapMain(main) and scaleAt(main) expose the same projection for overlays you draw yourself.

The invariant: the curve never writes a position

There is one rule that everything on this page obeys, and it is worth understanding why. The motion layer places each symbol by writing one coordinate on its view, and the reel later reads that coordinate back to work out which seat the view is in (in beginMotion, notifyLanded and _replaceSymbol). If the curve moved the view to its projected position, the reel would read a bent value and treat it as a flat one, and the error would compound on every round trip. So the curve never touches view.position. It hands the symbol a quad, and ReelSymbol.applyCellQuad must fit the art into that quad without moving the view; the base implementation pays for its fit entirely through the pivot.

Two set-level helpers measure through the same map so your overlays agree with the drum. ReelSet.getCellBounds(reel, cell) returns the axis-aligned bounding box of the projected quad; a payline drawn through its centre tracks the curve, while a rectangle outline on it is a hair loose on the narrow edge. getCellQuad(reel, cell) returns the four corners in ReelSet space, or null on a flat reel. Use the quad for hit areas in warp mode and for anything that should sit on the curve rather than around it.

Two ways to draw it

The model says where every point should go; something still has to draw it there. There are two renderers, chosen with curveMode, and the table sums up the trade. Symbol mode is the default and costs nothing, but only content that is a texture can be keystoned, and only when that texture owns its whole source. Warp mode bends anything at all, at the price of an extra render pass per reel per frame.

curveMode('symbol'), the defaultcurveMode('warp')
HowEach symbol is handed a quad and keystones its own texture through a small mesh.The whole reel is rendered to a texture every tick and the texture is bent through one mesh.
What bendsOnly textures that own their whole source: generated textures, single images, render textures. Everything else gets an affine fit.Everything inside the reel container: Spine, atlas sprites, text, effects.
CostNothing extra per frame.One extra render pass per reel per frame, plus a resample that makes hairline art slightly softer.
NeedsNothing.builder.renderer(app.renderer); build() throws without it.
Hit testingSymbols are real display objects.Symbols are inside a texture; use getCellQuad instead of screen-space tests.

Figure 2 is symbol mode, one frame for one symbol. Follow it top to bottom: the flat position is written first, as always; the curve converts that position into a quad; and the symbol decides what to do with it. Notice the fork at the bottom. A texture that owns its whole source goes through a small perspective mesh and really keystones. Anything else, including the common case of a sub-frame in a texture atlas, takes the affine fallback: scaled and positioned to fit the quad, but still a rectangle.

ReelMotion._render()flat main written first, as alwayscurve.quadFor(main, inset)view-local quad, null when flatsymbol.applyCellQuad(quad)SpriteSymbol, AnimatedSpriteSymbolPerspectiveCellPerspectiveMesh 10 x 10setCorners(quad), own UVsaffine fallbackatlas sub-frames, Spine, Graphicscontain-fit via pivot, no bendwhole-source textureotherwise
curveMode('symbol'), the default. Each cell is projected on its own and costs nothing extra: the flat position is written first, the curve hands the symbol a quad, and a texture that owns its whole source is keystoned through a mesh while anything else falls back to an affine fit.

The reason for the fork is that a PixiJS Container transform is affine: it can scale, move and rotate a cell, but it can never turn a rectangle into a trapezoid. Only content that is a texture can be keystoned, by drawing it on a mesh whose corners are the quad. PerspectiveCell (packages/pixi-reels/src/symbols/PerspectiveCell.ts) is that mesh, shared by SpriteSymbol and AnimatedSpriteSymbol. It allocates its PerspectiveMesh lazily, re-reads the texture on every apply so an animated symbol can swap frames, and rewrites the mesh's UVs from texture.uvs on every texture swap, because a mesh's 0..1 UVs address the whole sheet where a sprite's do not. It pivots the mesh on the quad's centre so a win pulse scales in place. canProjectTexture accepts only textures that own their whole source: generated textures, single images and render textures. SpriteSymbol.onActivate calls perspective.syncTexture so a pooled symbol keeps its quad when it is reused, and AnimatedSpriteSymbol pushes every frame change through.

Figure 3 is warp mode, one frame for one reel. The reel's container is taken off the stage and replaced by a mesh; every tick the container is rendered into a texture, and the mesh shows that texture with its vertices displaced onto the drum. Notice the last box: the symbols themselves are never handed a quad in this mode, so there is no risk of bending twice, and anything the engine lifts out of the reel draws flat above the drum.

reel.container leaves the stageReelWarp takes its place in maskedContainerRenderTexturereel box + one slotPitch per strip end+ curveBleed per side across itrenderer.render(container)every tick, even at restMeshPlane 16 x 16vertices displaced once per geometrycross toward focus, main through mapMainsymbols untouchedno quads handed out, no double bendlifted content draws flat above the drum
curveMode('warp'), which needs builder.renderer(app.renderer). The whole reel is rendered to a texture every tick and the texture is bent, so everything inside follows at one extra render pass per reel per frame; the symbols themselves are never handed a quad.

Warp mode (packages/pixi-reels/src/core/ReelWarp.ts) bends whatever is inside the reel, Spine skeletons, atlas sprites, text and effects alike, with no cooperation from the symbol, and it sidesteps the sub-frame problem because a render texture always owns its whole source. The texture is the reel box grown by one slotPitch at each end of the strip, since the drum's ends curve away from the window and the buffer cells fill that band, and by curveBleed per side across it, for art wider than its cell. It is created at the renderer's resolution. Each tick the source container is moved to the texture's origin plus that margin, rendered with clear: true, and moved back within the same synchronous block. The render runs even when the reel is at rest, because win pulses, cascade destroys and the spotlight all animate symbols on a resting reel, and the texture is all the player sees. The mesh's vertices are displaced once per geometry change, not per frame, and resize re-measures after a MultiWays reshape.

Two things change for your game code in warp mode. Symbols are no longer real display objects as far as the renderer is concerned, so hit-test through getCellQuad rather than against the sprites. And anything the engine lifts out of the reel container, unmask: true symbols at rest, the win spotlight and pin overlays, is not in the texture and draws flat above the drum; the builder tells you so with the warp-skips-unmask notice. build() throws if warp mode is chosen without renderer(...).

Where the camera sits

So far each reel has been its own drum with the camera straight in front of it. On a five-reel board that looks like five separate cylinders side by side. A real cabinet has one drum per reel but one pair of eyes, so the outer reels are seen slightly from the side and their cells lean in toward the middle of the board. curveFocus controls that lean. Figure 4 shows three reels under each setting; notice how the buffer cells of the outer reels shift toward the centre line as the weight rises, while the middle reel never changes.

curveFocus('reel')weight 0: own centrelinecurveFocus('set-lean')weight 0.5: halfwaycurveFocus('set')weight 1: board centre
curveFocus moves the cross coordinate each reel's cells converge on, three reels shown. At weight 0 it is the reel's own centreline; at 1 it is the middle of the board, so the outer reels lean in and the grid reads as one drum.

The focus is a point on the cross axis that a reel's cells converge toward as they recede. In words: start at the reel's own centre line, and move toward the centre of the whole board by a weight between 0 and 1. The three named settings are just weights: 'reel' is 0 (every reel is its own drum), 'set' is 1 (every reel converges on the board centre, so the grid reads as one drum) and 'set-lean' is halfway. The formula, reel-local, is focusCross = cellCross / 2 + weight * (setCentre - reelIndex * (cellCross + crossGap) - cellCross / 2), and the weights are CURVE_FOCUS_WEIGHT = { reel: 0, 'set-lean': 0.5, set: 1 }. In warp mode the same focus feeds the vertex displacement, so the whole texture leans.

Leaning has a side effect on masking. A cell that leans toward the board centre crosses out of its own column, and the default per-reel mask, RectMaskStrategy, would clip it at the column boundary. So any focus other than 'reel' switches the default mask to SharedRectMaskStrategy and logs the mask-auto-shared notice; an explicit .maskStrategy(...) always wins. The focus only has an effect alongside curve(...) or curvePerReel(...). The mask side of this is on viewport and masks.

The curve can be changed at runtime. ReelSet.setCurve(input) drives Reel.setCurve on every reel, and ReelMotion.setCurve first flattens every symbol with applyCellQuad(null) before dropping to amount: 0; without that, the last quad each symbol was handed would stay on screen. The reel curvature recipes show both modes, the focus settings and a payline drawn on the drum.

Defaults

The values this page relies on, with the file each one is set in.

ItemValueWhere
amount0 (flat); clamped to 0..1core/ReelCurve.ts
depthamount * 0.5, then min(depth, 0.9 * cos(amount * MAX_ARC))core/ReelCurve.ts
MAX_ARC / MIN_ARC / DEPTH_SAFETY1.0 rad / 1e-4 / 0.9core/ReelCurve.ts
curveFocus'reel' (weights reel 0, set-lean 0.5, set 1)core/ReelSetBuilder.ts
curveMode'symbol'core/ReelSetBuilder.ts
curveBleed0 px per side, warp onlycore/ReelSetBuilder.ts
PerspectiveCell VERTICES10 x 10symbols/PerspectiveCell.ts
ReelWarp GRID16 x 16 verticescore/ReelWarp.ts
Warp texture marginslotPitch at each strip end, renderer.resolutioncore/Reel.ts, core/ReelWarp.ts
Mask when focus != reelSharedRectMaskStrategy (auto, unless explicit)core/ReelSetBuilder.ts

Where this lives

packages/pixi-reels/src/core/
  • ReelCurve.ts ReelCurveConfig, resolveCurveConfig, CurveFocus, CurveMode, CURVE_FOCUS_WEIGHT, quadFor, mapMain, scaleAt
  • ReelWarp.ts the render-to-texture mesh, update, resize, _displace
  • Reel.ts _buildCurve, setCurve, _placeSymbolView, the warp hand-off in the constructor
  • ReelMotion.ts setCurve, quadFor in _render
  • ReelSet.ts getCellBounds, getCellQuad, setCurve
  • ReelSetBuilder.ts curve, curvePerReel, curveFocus, curveMode, curveBleed, renderer, the mask auto-pick
packages/pixi-reels/src/symbols/
  • PerspectiveCell.ts textureCellInset, canProjectTexture, PerspectiveCell
  • ReelSymbol.ts cellInset, applyCellQuad (affine fallback)
  • SpriteSymbol.ts, AnimatedSpriteSymbol.ts the two built-ins that project
config/types.ts
  • ReelCellQuad (box plus x0..y3), ReelCellInset (left, top, right, bottom as fractions)