topical media & game development

talk show tell print

graphic-processing-site-examples-Topics-Animation-AnimatedSprite-application.linux-source-Animation.pde / pde



  // Class for animating a sequence of GIFs
  
  class Animation {
    PImage[] images;
    int imageCount;
    int frame;
    
    Animation(String imagePrefix, int count) {
      imageCount = count;
      images = new PImage[imageCount];
  
      for (int i = 0; i < imageCount; i++) {
        // Use nf() to number format 'i' into four digits
        String filename = imagePrefix + nf(i, 4) + ".gif";
        images[i] = loadImage(filename);
      }
    }
  
    void display(float xpos, float ypos) {
      frame = (frame+1) % imageCount;
      image(images[frame], xpos, ypos);
    }
    
    int getWidth() {
      return images[0].width;
    }
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.