An image gallery
Updated
A UI Image that steps through three pictures with Previous and Next buttons; the caption waits for the image’s ready event and reports load errors.
Press Next and Previous to step through the pictures; the caption updates once each one has loaded. Drag outside the panel to orbit the camera, scroll to zoom.
An image gallery
#pragma lifecycle(startup)
const PHOTOS = [ { src: '/example-assets/lemon-decal.png', caption: 'Lemon slice' }, { src: '/example-assets/bang.png', caption: 'Comic bang' }, { src: '/example-assets/alpha.png', caption: 'Star burst' },];let index = 0;let photo;let caption;
function show() { photo.setProps({ src: PHOTOS[index].src }); caption.setProps({ text: 'Loading…' });}
function startup() { photo = findEntity('Photo').getComponent(UIImageComponent); caption = findEntity('Caption').getComponent(UILabelComponent);
on('gallery:photo', (event) => { if (event.eventType === EventType.UIImage.Ready) { caption.setProps({ text: `${PHOTOS[index].caption} (${index + 1} of ${PHOTOS.length})` }); log('showing', PHOTOS[index].caption, `${event.data.width}×${event.data.height}`); } if (event.eventType === EventType.UIImage.Error) caption.setProps({ text: 'Could not load this picture.' }); }); on('gallery:prev', (event) => { if (event.eventType !== EventType.UIButton.Press) return; index = (index + PHOTOS.length - 1) % PHOTOS.length; show(); }); on('gallery:next', (event) => { if (event.eventType !== EventType.UIButton.Press) return; index = (index + 1) % PHOTOS.length; show(); });
show();}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.
StickerGallery.xrproj