Cycle posters on click
Updated
A poster on a gallery wall shows the next picture each time it is clicked, fitted inside 1.6 × 1.6 m with sizing auto, and the script logs each image’s pixel size from its ready event.
Click the poster to show the next picture; the log gives each one's size. Drag to orbit the camera, scroll to zoom.
Cycle posters on click
#pragma lifecycle(startup)
const POSTERS = [ '/example-assets/lemon-decal.png', '/example-assets/bang.png', '/example-assets/alpha.png',];
let poster;let index = 0;
function startup() { poster = findEntity('Poster').getComponent(ImageComponent); poster.setProps({ src: POSTERS[0], sizing: 'auto', width: 1.6, height: 1.6 });
on('poster', (event) => { if (event.eventType === EventType.Selectable.Select) { findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again index = (index + 1) % POSTERS.length; poster.setProps({ src: POSTERS[index] }); } if (event.eventType === EventType.Image.Ready) { log(`Poster ${index + 1}: ${event.data.width} x ${event.data.height} px`); } if (event.eventType === EventType.Image.Error) { console.warn(`Poster ${index + 1} failed: ${event.data.message}`); } });}How it works
Section titled “How it works”The script is explained step by step in Cycle posters on click.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
PosterCycle.xrproj