There are two high level functions for playing FLI/FLC animations: play_fli(), which reads the data directly from disk, and play_memory_fli(), which uses data that has already been loaded into RAM. Apart from the different sources of the data, these two functions behave identically. They draw the animation onto the specified bitmap, which should normally be the screen. Frames will be aligned with the top left corner of the bitmap: if you want to position them somewhere else you will need to create a sub-bitmap for the FLI player to draw onto.
If the callback function is not NULL it will be called once for each frame, allowing you to perform background tasks of your own. This callback should normally return zero: if it returns non-zero the player will terminate (this is the only way to stop an animation that is playing in looped mode).
The FLI player returns FLI_OK if it reached the end of the file, FLI_ERROR if something went wrong, and the value returned by the callback function if that was what stopped it. If you need to distinguish between different return values, your callback should return positive integers, since FLI_OK is zero and FLI_ERROR is negative.
Note that the FLI player will only work when the timer module is installed, and that it will alter the palette according to whatever palette data is present in the animation file.
Occasionally you may need more detailed control over how an FLI is played, for example if you want to superimpose a text scroller on top of the animation, or to play it back at a different speed. You could do both of these with the lower level functions described below.
/* Let users skip looped animations. */ int check_escape_key(void) { if (key[KEY_ESC]) return 1; else return 0; } ... int ret = play_fli("animlogo.fli", screen, 1, check_escape_key); if (ret == FLI_ERROR) abort_on_error("Error playing intro!");
Return value: The FLI player returns FLI_OK if it reached the end of the file, FLI_ERROR if something went wrong, and the value returned by the callback function if that was what stopped it.
See also: play_memory_fli, install_timer, fli_frame.
Playing animations from memory is obviously faster than cuing them directly from disk, and is particularly useful with short, looped FLI's. Animations can easily get very large, though, so in most cases you will probably be better just using play_fli(). You can think of this function as a wrapper on top of open_memory_fli(), next_fli_frame() and close_fli(). Example:
int ret = play_memory_fli(anim_data, screen, 0, NULL); if (ret == FLI_ERROR) abort_on_error("Corrupted animation data?");
Return value: The FLI player returns FLI_OK if it reached the end of the file, FLI_ERROR if something went wrong, and the value returned by the callback function if that was what stopped it.
See also: play_fli, install_timer, fli_frame.
if (open_fli("intro.fli") == FLI_ERROR) abort_on_error("Error playing intro");
Return value: Returns FLI_OK on success, FLI_ERROR if something went wrong, like trying to open another FLI file without closing the previous one.
See also: close_fli, next_fli_frame, fli_bitmap, fli_palette.
See also: open_fli.
while (next_fli_frame(0) == FLI_OK) { /* Do stuff, like play audio stream or check keys to skip animation. */ /* Rest some time until next frame... */ }
Return value: Returns FLI_OK on success, FLI_ERROR or FLI_NOT_OPEN on error, and FLI_EOF on reaching the end of the file.
See also: open_fli, fli_bitmap, fli_palette, fli_timer, fli_frame.
See also: next_fli_frame, fli_bmp_dirty_from, fli_palette.
See also: next_fli_frame, fli_pal_dirty_from, fli_bitmap.
if (fli_bmp_dirty_from <= fli_bmp_dirty_to) blit(fli_bitmap, screen, 0, fli_bmp_dirty_from, 0, fli_bmp_dirty_from, fli_bitmap->w, fli_bmp_dirty_to - fli_bmp_dirty_from + 1);
See also: fli_bitmap, reset_fli_variables.
if (fli_pal_dirty_from <= fli_pal_dirty_to) set_palette_range(fli_palette, fli_pal_dirty_from, fli_pal_dirty_to, 1);
See also: fli_palette, reset_fli_variables.
See also: fli_bmp_dirty_from, fli_pal_dirty_from.
while (next_fli_frame(0) == FLI_OK) { if (fli_frame == 345) play_sample(trumpet_sound, 255, 128, 1000, 0); /* Rest some time until next frame... */ }
See also: play_fli, play_memory_fli, next_fli_frame.
while (next_fli_frame(0) == FLI_OK) { /* Do stuff, like play audio stream or check keys to skip animation. */ /* Rest some time until next frame... */ while (fli_timer <= 0) rest(0); }
See also: install_timer, next_fli_frame.