Skip to content

LaserPointerNode

LaserPointerNode (from scenerystack/scenery-phet) draws a laser-pointer body — a tapered nozzle and casing, pointing right by default with its origin at the output nozzle — with an optional built-in on/off button wired to a boolean Property. It's the standard "light source the user can turn on and point" graphic in optics/light sims (e.g. bending-light-style sims), and can also represent a plain flashlight-style light source with hasButton: false.

ts
import { LaserPointerNode } from 'scenerystack/scenery-phet';
import { BooleanProperty } from 'scenerystack/axon';

A minimal example

ts
const onProperty = new BooleanProperty( false );

const laserPointerNode = new LaserPointerNode( onProperty, {
  tandem: tandem.createTandem( 'laserPointerNode' ),
  hasGlass: true // draws a small lens at the nozzle output
} );

onProperty is two-way bound: toggling the built-in button flips it, and setting it programmatically updates the button's pressed appearance.

Options

OptionDefaultEffect
bodySize / nozzleSizeDimension2(110,78) / Dimension2(20,60)Dimensions of the main casing and the narrower nozzle
topColor / bottomColor / highlightColorgrays / near-whiteVertical gradient colors for both body and nozzle
hasButtontrueWhether an on/off button is drawn at all — other button options are ignored if false
buttonType'toggle''toggle' uses a RoundStickyToggleButton (press to latch on, press again to turn off); 'momentary' uses a RoundMomentaryButton (on only while held)
buttonOptions{ baseColor: 'red', radius: 22, … }Forwarded to the underlying round button
getButtonLocationbodyNode => bodyNode.centerFunction computing where the button sits within the body
hasGlassfalseDraws a semicircular lens ShadedSphereNode at the nozzle output — a visual cue that this is a non-laser light source, without moving the Node's origin
glassOptionstuned defaultsheightProportion/proportionStickingOut control the lens's size and how far it protrudes, plus standard ShadedSphereNode coloring

Instance member

MemberTypeDescription
onOffButtonNode | nullRead-only reference to the button Node (if hasButton is true), safe to add listeners to but not to mutate structurally

Static member

MemberDescription
LaserPointerNode.DEFAULT_LASER_NODE_OPTIONSThe frozen default options object, useful for building a variant that overrides only a few fields

tandem defaults to Tandem.REQUIRED

Like other instrumentable scenery-phet components, LaserPointerNode's default options set tandem: Tandem.REQUIRED and a tandemNameSuffix of ['LaserPointerNode', 'LightNode'] — omitting a real tandem asserts in an instrumented build. Always pass tandem: someTandem.createTandem( '...' ) explicitly. See Tandem for why Tandem.REQUIRED exists as a sentinel rather than a usable default.