English
Appearance
English
Appearance
Related reference: Scene API / Animated Images
The current advanced Web API provides creation and playback control for GIF animated-image objects.
const gif = await api.createAnimatedImage('https://your.domain.com/fireworks.gif');
await api.add(gif);ArrayBuffer input is also supported.
const paused = await api.getAnimatedImagePaused(gif);await api.playAnimatedImage(gif, 0);playAnimatedImage() also supports a second loopCount argument, which is useful when you want the animation to play only a certain number of times.
0 means infinite looping. If you omit the argument, the GIF's built-in loop value is used.
await api.pauseAnimatedImage(gif);await api.stopAnimatedImage(gif);After stopping, the animation usually returns to its initial state.
play - fires when the animated image starts playingfunction onPlay(event) {
const { type, target } = event;
}
await api.on('play', onPlay, gif);pause - fires when the animated image pausesfunction onPause(event) {
const { type, target } = event;
}
await api.on('pause', onPause, gif);ended - fires when the animated image finishes naturallyfunction onEnded(event) {
const { type, target } = event;
}
await api.on('ended', onEnded, gif);loop - fires when the animated image completes one loop during looping playbackfunction onLoop(event) {
// loopedTimes - how many loops have completed
const { type, target, loopedTimes } = event;
}
await api.on('loop', onLoop, gif);Animated-image objects can still use the common object APIs:
await api.setPosition(gif, 0, 1, 0);
await api.setScale(gif, 1.5, 1.5, 1.5);
await api.setObjectVisible(gif, true);If you need finer-grained control, such as frame-by-frame control or alpha channels, video or glTF animation is usually a better fit than GIF.