A slideshow that fades between pictures
Updated
A picture frame holds each slide for four seconds, fades it out, swaps the file, waits for the new image’s ready event and fades back in, all from an async loop on the Image entity.
Watch the frame fade from one picture to the next every few seconds. Drag to orbit the camera, scroll to zoom.
A slideshow that fades between pictures
#pragma lifecycle(startup)
const SLIDES = [ '/example-assets/lemon-decal.png', '/example-assets/bang.png', '/example-assets/alpha.png',];const HOLD_MS = 4000;const FADE_SECONDS = 0.6;
let image;
function wait(ms) { return new Promise((done) => delay(done, ms));}
// Resolves on the next ready or error event of this image.function nextLoad() { return new Promise((done) => { const stop = on('slides', (event) => { if (event.eventType === EventType.Image.Ready || event.eventType === EventType.Image.Error) { stop(); done(); } }); });}
function fade(from, to) { return Tween.value(from, to, (value) => image.setProps({ opacity: value }), { duration: FADE_SECONDS, ease: Ease.InOutSine, });}
async function startup() { image = self.parent.getComponent(ImageComponent); let index = 0;
for (;;) { await wait(HOLD_MS); await fade(1, 0);
index = (index + 1) % SLIDES.length; const loaded = nextLoad(); image.setProps({ src: SLIDES[index] }); await loaded;
await fade(0, 1); }}How it works
Section titled “How it works”The script is explained step by step in A slideshow that fades between pictures.
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.
FadingSlideshow.xrproj