Skip to content

LightBulbNode

LightBulbNode (from scenerystack/scenery-phet) draws a light bulb that glows in response to a brightnessProperty in the range [0, 1]: at 0 only the "off" bulb image is shown, and as brightness rises the "on" image fades in (via opacity) while a LightRaysNode radiates more and longer rays behind it. It's the standard "is this circuit/light source active, and how strongly" visual used across circuit and light-related simulations.

ts
import { LightBulbNode } from 'scenerystack/scenery-phet';
import { NumberProperty } from 'scenerystack/axon';

A minimal example

ts
const brightnessProperty = new NumberProperty( 0 ); // 0 (off) to 1 (full brightness)

const bulbNode = new LightBulbNode( brightnessProperty, {
  bulbImageScale: 0.5
} );

// Later, as current/voltage changes:
brightnessProperty.value = 0.75;

Constructor

ts
new LightBulbNode(
  brightnessProperty: TReadOnlyProperty<number>,
  providedOptions?: LightBulbNodeOptions
)

Options

OptionDefaultEffect
bulbImageScale0.33Scale applied to both the "on" and "off" bulb images
lightBulbOnImage / lightBulbOffImagePhET's standard bulb mipmapsOverride to use custom bulb artwork
lightRaysNodeOptions{}Options forwarded to the internal LightRaysNode (x/y are computed automatically to center the rays behind the bulb)

brightnessProperty must stay within [0, 1], and updates pause while invisible

LightBulbNode asserts that brightnessProperty.value is between 0 and 1 inclusive. For performance, it also skips recomputing the "on" image's opacity and the rays while the node is invisible, and only catches up (via a visibleProperty listener) the next time it becomes visible — so don't expect a LightBulbNode hidden behind another screen's content to be pixel-accurate the instant you show it if brightness changed many times while hidden; it will simply jump straight to the current value.

LightBulbNode links to brightnessProperty for the lifetime of the Node and unlinks in its own dispose() override — see Dispose and Memory Management if you're creating and destroying bulbs dynamically (e.g. one per circuit element in a list).