VgaGames4 - sprite man-pages

[.. upper level ..]

Sprite functions

A sprite is mainly a collection of images, optionally with sound files, which define an animated image. The definition of a sprite is realized with a text-file (see vg4->sprite->load()). The images will be returned successive with vg4->sprite->next(), until the sprite ends (if not infinite). See also the command: vg4 sprite -h


Example

screenshot1.gif
example.c

/* load a sprite, show it until it ends */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <vgagames4.h>

int main(int argc, char **argv) {
  struct VG_Sprite *sprt;
  struct VG_Image *imgp;
  struct VG_ImagecopyAttr iattr;

  (void)argc; (void)argv;

  /* initialize and open window */
  if (!VG_init("test")) { exit(1); }
  if (!vg4->window->open(VG_WINDOW_SIZE_LOW, VG_WINDOW_SCALE_BEST)) { VG_dest(); exit(1); }

  /* load sprite */
  sprt = vg4->sprite->load("boy.sprite");
  if (sprt == NULL) { VG_dest(); exit(1); }

  for (;;) {
    /* get next sprite-element, check for ending sprite */
    if (!vg4->sprite->next(sprt, &imgp, &iattr)) { break; }

    /* copy image to window, if an image was returned */
    vg4->window->clear();
    if (imgp != NULL) {
      vg4->window->copy(imgp, NULL, &iattr);
    }

    vg4->window->flush();
    vg4->misc->wait_time(50);
  }

  vg4->sprite->destroy(sprt);

  /* destroy and exit */
  VG_dest();
  exit(0);
}


boy.sprite

[SPRITE LIFETIME=3]

IMAGE: boy01.bmp
IMAGE: boy02.bmp
IMAGE: boy03.bmp
IMAGE: boy04.bmp
IMAGE: boy05.bmp
IMAGE: boy06.bmp
IMAGE: boy07.bmp
IMAGE: boy08.bmp
IMAGE: boy09.bmp
IMAGE: boy10.bmp
IMAGE: boy11.bmp
IMAGE: boy12.bmp
IMAGE: boy13.bmp
IMAGE: boy14.bmp
IMAGE: boy15.bmp