Skip to content

Spot light effects

Updated

Two components add to a Spot Light. A Spot Light Beam makes its cone visible in the air, like a stage light in a smoky room or a lighthouse at night. A Spot Light Projector shines an image through the light, like a gobo or a slide projector: a logo on a wall, leaves dappling a floor, a window pattern across a room. Both go on the Spot Light entity and follow the light’s own changes as they happen.

  • Both components work only with a Spot Light. Read that page first, especially how the entity’s rotation aims the light.
  • The projector needs the light to cast shadows, through an enabled Light Shadow.
  • Components are reached with entity.getComponent(Class) and changed with setProps. See Components.

SpotLightBeamComponent (comp-spot-light-beam) shows the light’s beam as a filled shaft of its colour along its aim, as long as its length and as wide as the light’s angle. It is a soft glow, brightest at the lamp and on its axis, fading out over its last stretch so it shows no hard end.

Prop Type Default Description
opacity number 0.25 How bright the beam is, 0 to 1. The default is a subtle glow.
length number 0 Length in metres, 0–1000. 0 takes the light’s distance, or 5 m when it has none.

It sends no events.

  • Ending at the floor. Set length to about where the beam meets the floor: it has faded out there, without shortening the light itself.
  • Follows the light. It refits when the light’s colour, angle or distance changes, never per frame. It shows nothing while the Spot Light is disabled or has a zero angle. It needs no shadows.
  • From inside. The beam is computed per pixel from where the view ray enters the cone, so the camera’s near plane never cuts it as you walk in or out. The trade-off: objects between the camera and the beam do not hide it.
  • XR. Each eye of a headset computes its own view of the beam, so both eyes agree.

Cost. One transparent, additive draw per beam. Every beam shares the same geometry and shader. Mind the fill rate on phones and headsets: a beam filling the view costs its work at every pixel.

SpotLightProjectorComponent (comp-spot-light-projector) makes the light project an image. The image works as a stencil: it decides where light passes, and the light keeps its own colour.

  • A transparent image (a PNG or an SVG with clear parts): the light shines where the image is opaque; where it is clear, the light is blocked.
  • An opaque image (every JPG, a PNG with no transparency): its brightness is the stencil. White lets the light through, black blocks it, and grey dims it as much as it looks dark, so gradients show. A very bright light can wash the lighter greys out: lower its intensity to see them.

Whether an image counts as transparent is decided once, when it loads: a single clear texel makes it transparent.

Prop Type Default Description
src string '' The image to project, a PNG, a JPG or an SVG: a URL, an asset reference or a data:image/ URL. Empty projects nothing.
zoom number 1 How far it zooms into the image, 0.001–10. 1 fills the cone, less shrinks the image with the light blocked around it, more zooms in.
Method What it does
load() Returns a promise that resolves once the current image has loaded or failed.

It sends no events.

  • Images. PNG, JPG (.jpg or .jpeg) and SVG only. An image smaller than 512 × 512, or with no size of its own, is drawn at that size, so an SVG stays sharp. A file named as any other format warns and projects nothing. src is an asset prop: it is preloaded and packaged with the project.
  • Rolling. The image turns with the light: rolling the Spot Light entity about its aim rolls what it projects.
  • Moving. Rotate the entity, from a script or with an Animation Timeline, to sweep the projection across a scene.

Cost. The stencil is drawn when the image loads and when zoom changes, never per frame otherwise. Setting a projection makes every lit material compile once, since the image becomes part of the light’s calculation.

The entity Logo Projector is a Spot Light with an enabled Light Shadow, a Spot Light Beam and a Spot Light Projector.

ProjectorSetup.jx
#pragma lifecycle(startup)
async function startup() {
const lamp = findEntity('Logo Projector');
// A faint shaft of light that fades out where it meets the wall, 6 m away.
lamp.getComponent(SpotLightBeamComponent).setProps({ opacity: 0.15, length: 6 });
// Project the logo, slightly smaller than the cone.
const projector = lamp.getComponent(SpotLightProjectorComponent);
projector.setProps({ src: '/example-assets/bang.png', zoom: 0.8 });
await projector.load();
log('Logo is on the wall');
}
  • setProps({ opacity, length }) on the beam changes its look; it follows the light’s colour and angle by itself.
  • Setting src starts loading the image. await projector.load() waits until it has loaded (or failed) before logging.
  • zoom: 0.8 leaves a ring of blocked light around the logo, so it reads as a clean shape on the wall.
  • startup is async so it can await.

Every five seconds the projector shows the next image in a list.

SlideShow.jx
#pragma lifecycle(startup)
const SLIDES = [
'/example-assets/lemon-decal.png',
'/example-assets/bang.png',
'/example-assets/alpha.png',
];
const SECONDS_PER_SLIDE = 5;
async function startup() {
const projector = self.parent.getComponent(SpotLightProjectorComponent);
let index = 0;
for (;;) {
projector.setProps({ src: SLIDES[index] });
await projector.load(); // show it as soon as it is ready
await new Promise((done) => delay(done, SECONDS_PER_SLIDE * 1000)); // then hold it
index = (index + 1) % SLIDES.length;
}
}
  • This Behavior entity is a child of the Spot Light, so self.parent is the light.
  • delay(fn, ms) runs fn later; wrapping it in a Promise lets the async loop wait. Scripts have no setTimeout.
  • await projector.load() waits for each new image, so the five seconds start only once it is showing.
  • When the script stops, its pending delay is cancelled and the loop never resumes, so nothing leaks.

The searchlight’s Spot Light has a Spot Light Beam. It sweeps left and right and its beam brightens when the player presses F.

Searchlight.jx
#pragma lifecycle(startup, update)
const SWEEP = DEG_TO_RAD(40); // how far it turns each way
const SPEED = 0.6; // radians of phase a second
let light;
let beam;
let baseYaw = 0;
let phase = 0;
function startup() {
light = self.parent;
beam = light.getComponent(SpotLightBeamComponent);
baseYaw = light.rotation.y;
beam.setProps({ opacity: 0.2, length: 8.5 }); // ends where the beam meets the floor
}
function update(dt) {
phase += dt * SPEED;
light.rotation.y = baseYaw + Math.sin(phase) * SWEEP;
if (Input.keyboard.isKeyReleased(Key.F)) {
Tween.value(0.6, 0.2, (value) => beam.setProps({ opacity: value }), { duration: 1.5, ease: Ease.OutCubic });
}
}
  • Rotating the entity aims the light; the beam follows on its own because it is part of the same entity.
  • Writing rotation.y directly is fine for a purely visual object moved every frame.
  • The flash tweens the beam’s opacity from bright back to normal through setProps.
  • The beam is not hidden by the floor, so length ends it where it meets the floor: the lamp is 4.3 m up and tilted about 31° down, which puts the floor about 8.5 m along the beam. The beam fades out at its end.

When the show starts (signal show/start), the projected image grows from a pinpoint to full size.

IrisOpen.jx
#pragma lifecycle(startup)
let projector;
function startup() {
projector = findEntity('Stage Projector').getComponent(SpotLightProjectorComponent);
projector.setProps({ zoom: 0.05 }); // almost closed
on('show/start', async () => {
await Tween.value(0.05, 1, (value) => projector.setProps({ zoom: value }), {
duration: 1.2,
ease: Ease.OutQuad,
});
log('Iris open');
});
}
  • A zoom below 1 shrinks the image inside the cone and blocks the light around it, so a tiny zoom looks like a closed iris.
  • Each zoom change redraws the stencil. A short opening is fine; do not animate zoom continuously, especially on mobile.
  • emit('show/start') from any script, or a Signal Emitter, triggers it.

Clicking a button entity (with a Selectable and a Signal Emitter whose signal is projector/next) switches between a day and a night pattern, and dims the beam at night.

PatternSwitch.jx
#pragma lifecycle(startup)
const DAY = { src: '/example-assets/lemon-decal.png', zoom: 1 };
const NIGHT = { src: '/example-assets/alpha.png', zoom: 1.4 };
async function startup() {
const lamp = findEntity('Window Light');
const projector = lamp.getComponent(SpotLightProjectorComponent);
const beam = lamp.getComponent(SpotLightBeamComponent);
let night = false;
projector.setProps(DAY);
await projector.load();
on('projector/next', async (event) => {
if (event.eventType !== EventType.Selectable.Select) return;
findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again
night = !night;
projector.setProps(night ? NIGHT : DAY);
beam.setProps({ opacity: night ? 0.08 : 0.2 });
await projector.load();
log(night ? 'Night pattern' : 'Day pattern');
});
}
  • Both props change in one setProps call, so the new image and its zoom appear together.
  • The SVG window pattern stays sharp at any size; the PNG star field uses its transparency as the stencil.
  • The beam is a separate component, changed independently.
  • The projector shows nothing. The Spot Light needs an enabled Light Shadow. Also check the file is a PNG, JPG or SVG.
  • Putting the effects on a Point Light. Both components work only with a Spot Light.
  • A beam that ends abruptly at a wall or seems to go through the floor. Set length to about where the beam meets the surface.
  • Expecting objects to hide the beam. Objects between the camera and the beam do not cover it.
  • Animating zoom every frame. Each change redraws the stencil. Animate briefly, or rotate the entity instead.
  • A projected gradient that looks flat. A very bright light washes out light greys. Lower the light’s intensity.
  • Too many beams on mobile. Each one is a transparent draw over every pixel it covers.