Skip to content

Path

Path (from scenerystack/scenery) is a Node that draws an arbitrary kite Shape — the general-purpose way to render vector graphics that aren't a plain circle, rectangle, or line. Circle, Rectangle, and Line are all Path subclasses that build their shape for you from simpler parameters; reach for Path directly when you need a custom outline.

ts
import { Path } from 'scenerystack/scenery';
import { Shape } from 'scenerystack/kite';

const triangle = new Shape()
  .moveTo( 0, 0 )
  .lineTo( 40, 0 )
  .lineTo( 20, -30 )
  .close();

const triangleNode = new Path( triangle, {
  fill: 'rebeccapurple',
  stroke: 'black',
  lineWidth: 2
} );

Options

OptionEffect
shapeThe Shape (or SVG path-data string, or null for nothing drawn) to render — see InputShape
shapePropertySets the shape via a TReadOnlyProperty<Shape | string | null> instead of a plain value
boundsMethodHow self bounds are computed: 'accurate' (default, exact stroked bounds), 'unstroked', 'tightPadding', 'safePadding', or 'none'
fillFill paint — a CSS color string, Color, LinearGradient, RadialGradient, or Pattern (from Paintable, shared with Text)
strokeStroke paint, same paint types as fill
lineWidthWidth of the stroked outline
lineCap / lineJoin / miterLimitStroke cap/join rendering, matching the Canvas 2D API
lineDash / lineDashOffsetDash pattern for the stroke

All Path subclasses also accept the full set of Node options (x, scale, visible, inputListeners, layoutOptions, …).

Don't mutate a shared Shape in place

If a Shape isn't marked immutable (shape.makeImmutable()), Path attaches a listener so it re-renders when the shape mutates — which also means the Path keeps a reference to the Shape (and vice versa) for as long as that link is alive. Reusing one mutable Shape instance across many Paths can create surprising update coupling and memory retention; prefer building each Path's shape independently, or call path.dispose() / set path.shape = null when finished with it.