A GIF sticker that pauses on click
Updated
An animated GIF on an easel that the player pauses and resumes by clicking it; the script follows the GIF’s play and pause events and lowers the frame rate on phones and headsets.
Click the horses to pause them; click again to resume. Drag to orbit the camera, scroll to zoom.
A GIF sticker that pauses on click
#pragma lifecycle(startup)
#if IS_MOBILE || IS_HEADSETconst FPS = 12;#elseconst FPS = 24;#endif
let gif;let playing;
function startup() { gif = self.parent.getComponent(GIFComponent); gif.setProps({ maxFps: FPS, controls: false }); playing = gif.props.autoplay; // an autoplaying GIF may start before this script does
on('sticker', (event) => { switch (event.eventType) { case EventType.GIF.Ready: if (!event.data.animated) log('This GIF has a single frame'); break; case EventType.GIF.Play: playing = true; break; case EventType.GIF.Pause: playing = false; break; case EventType.Selectable.Select: findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again if (playing) gif.pause(); else gif.play(); break; } });}How it works
Section titled “How it works”The script is explained step by step in A GIF sticker that pauses 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.
GifSticker.xrproj