An animation holds the frames of an animated image file as images, together with the time each frame is shown. It reads animated PNG (APNG), GIF, WebP and AVIF files and Windows animated cursors (ANI). A file that is not animated becomes an animation of one frame.
An animation does not play itself. A bitmap shows it:
new(A, animation('spinner.png')),
send(Window, display, new(BM, bitmap(A))),
send(BM, play).
All frames are decoded when the animation is created, so a long animation with large frames takes a lot of memory. Loading the same file as an image gives its first frame.
An animation can also be made from images using animation->append,
or by recording a window using animation->record,
and saved as an animated image file using animation->save.
For example, to record a window for 5 seconds as an animated GIF:
new(A, animation), send(A, record, Window, 0.1), ... % 5 seconds later send(A, stop), send(A, save, 'window.gif').
<-size:
the file describes the complete picture for each frame, also if it only
stores what changed.->play
shows frames of 10 milliseconds or less for 100 milliseconds, as web
browsers do.->save
writes it.->save
writes them. PNG and WebP files hold all of them; GIF files only the
description.|window*->record
is recording, or @nil.
.path,
as for image->initialise.
The format is found from the data, not the name of the file. Fails with
a message if the file cannot be read or is not an image. Without a file,
the animation has no frames: use animation->append
or animation->record
to add them.<-size;
images of another size are scaled to it.|window,
interval=[real]<-image as a frame now and
every interval seconds (default 0.1) until animation->stop,
or until from is destroyed. Each frame is shown for the
interval.png writes an
animated PNG (APNG). If format is omitted, the extension of
the file selects it. quality is used by WebP and AVIF. animation<-loop_count
and the texts such as animation<-title
are saved with the frames, as far as the format can hold them. Fails
with a message if there are no frames or the format cannot be written:
whether WebP and AVIF are available depends on how SDL_image was built.