Skip to content

Image

Updated

An image on a plane or a 360 sphere.

Type
ent-image
Script class
ImageEntity
Family
Media

An Image entity shows a still picture in the world: a poster on a wall, a logo above a door, a photo on a stand, or a 360 panorama around the player. It decodes the file through the browser, so it accepts the formats the browser does: PNG, JPEG, WebP, a static GIF, and AVIF where the browser supports it. The picture is unlit: it keeps its own colours whatever the scene lighting.

The picture lies on a flat plane in the entity’s local X/Y plane. It is cover-fitted: it fills the plane without stretching, and whatever overflows is cropped. It looks the same in the editor and in play, and it loads before the scene is revealed.

Pick a sibling when the content is different: Image KTX2 for large or numerous pictures on phones and headsets, Image SVG for vector logos that must stay sharp up close, Image GIF or Lottie for animation, and a UI Image for a picture inside a UI panel.

The props that matter most, on its Image component (ImageComponent in scripts):

  • src: the picture, as a URL or an asset from your project. Changing it loads the new picture.
  • width and height: the plane’s size in metres. With sizing: 'auto' they become bounds, and the plane takes the picture’s own proportions inside them instead of cropping it.
  • opacity, color and grayscale: fade the picture, tint it, or take its colour out (0 is full colour, 1 is black and white).
  • zoom: above 1 zooms into the centre of the picture.
  • projection and side: equirectangular wraps the picture on a sphere for a 360 panorama; set side to back to see it from inside, and width becomes the sphere’s radius.
  1. Add an Image entity to the scene and give it a clear name, such as Poster.
  2. Set its src to a picture.
  3. Set width and height to the size you want in metres. If pictures of different shapes will be shown, set sizing to auto so none is cropped.
  4. Move, turn and scale it with its Transform like any other entity.
  5. For a 360 panorama, set projection to equirectangular, side to back and width to a radius large enough to surround the player, such as 50.
  6. To let scripts know when the picture has loaded or failed, add a Signal Emitter and set its signal. To make it clickable, add a Selectable as well.

Show a different picture when a script raises a signal.

PosterSwap.jx
#pragma lifecycle(startup)
// Scene: an Image entity "Poster".
let poster;
function startup() {
poster = findEntity('Poster').getComponent(ImageComponent);
on('poster/night', () => poster.setProps({ src: '/assets/poster-night.jpg' }));
on('poster/day', () => poster.setProps({ src: '/assets/poster-day.jpg' }));
}

How it works:

  • findEntity('Poster') finds the entity once, and getComponent(ImageComponent) reaches its picture.
  • setProps({ src }) loads the new picture; the old one stays until the new one is ready.
  • Any script, or a button’s Signal Emitter on poster/night, triggers the change.

Show the next picture each time the player clicks the frame, without cropping portrait and landscape pictures.

Gallery.jx
#pragma lifecycle(startup)
// Scene: an Image entity "Gallery" with a Selectable and a
// Signal Emitter on the signal 'gallery'.
const PICTURES = ['/assets/art-1.jpg', '/assets/art-2.jpg', '/assets/art-3.jpg'];
let index = 0;
let image;
function startup() {
image = findEntity('Gallery').getComponent(ImageComponent);
image.setProps({ src: PICTURES[0], sizing: 'auto', width: 1.6, height: 1.6 });
on('gallery', (event) => {
if (event.eventType === EventType.Selectable.Select) {
findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again
index = (index + 1) % PICTURES.length;
image.setProps({ src: PICTURES[index] });
} else if (event.eventType === EventType.Image.Ready) {
log('Showing', PICTURES[index], event.data.width, 'x', event.data.height, 'px');
} else if (event.eventType === EventType.Image.Error) {
log('Cannot load', PICTURES[index], event.data.message);
}
});
}

How it works:

  • sizing: 'auto' with 1.6 × 1.6 bounds fits every picture inside the same square, whatever its shape.
  • One Signal Emitter carries both the Selectable’s clicks and the Image’s own events; event.eventType tells them apart.
  • Image::ready reports the picture’s size in pixels, and Image::error a message when it cannot load.

Fade the picture out, change it, and fade the new one in once it has loaded.

SlideFade.jx
#pragma lifecycle(startup)
// Scene: an Image entity "Slides" with a Signal Emitter on the signal 'slides'.
// Something emits 'slides/show' with { src }.
let image;
let pending = null;
function startup() {
image = findEntity('Slides').getComponent(ImageComponent);
on('slides/show', async (data) => {
await Tween.value(image.props.opacity, 0, (v) => image.setProps({ opacity: v }), { duration: 0.4 });
pending = data.src;
image.setProps({ src: data.src });
});
on('slides', (event) => {
if (!pending) return;
if (event.eventType !== EventType.Image.Ready && event.eventType !== EventType.Image.Error) return;
pending = null;
Tween.value(0, 1, (v) => image.setProps({ opacity: v }), { duration: 0.4 });
});
}

How it works:

  • Tween.value(from, to, onValue, options) passes a number moving from from to to to onValue each frame; here it drives opacity. Awaiting it waits for the fade-out to end.
  • The new src is set while the picture is invisible, so the swap never shows.
  • The fade-in starts on Image::ready, or on Image::error so the frame never stays empty.
  • Changing src reloads the picture; every other prop updates the live surface without reloading, so animating opacity, color or zoom is cheap.
  • For a row of identical pictures, add a Cache Mesh to each: copies with the same source and settings are drawn together in one draw call. Do not use it on a surface under a mask.

What a new Image is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.

Component Type Role Per entity What it does
Layer comp-layer Required One Puts the entity on a render/raycast layer so cameras and rays can include or skip it.
Lock comp-lock Required One Editor-only flag that stops the entity from being selected or moved.
Enable comp-enable Required One Turns the entity and its children on or off: hides them and stops their behavior.
Transform comp-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
Image comp-image Required One An image on a plane or a 360 sphere.

You can also add 19 optional components, such as Animation Graph, Animation Timeline, Attribution, Billboard, Cache Mesh, Enable On Signal.

The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).

Prop Default Range
width 1 0 ≤ x ≤ 10000
height 1 0 ≤ x ≤ 10000
color "#ffffff"
zoom 1 0.001 ≤ x ≤ 1000
grayscale 0 0 ≤ x ≤ 1
opacity 1 0 ≤ x ≤ 1
projection "planar"
side "double"

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • Image::ready
  • Image::error

Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My Image.

ImageEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My Image');
if (!(entity instanceof ImageEntity)) return;
// Its Image component holds the settings listed under Props.
const component = entity.getComponent(ImageComponent);
log('width is', component.props.width);
component.setProps({ width: 1.5 });
}