import processing.core.PApplet; import processing.core.PImage; import processing.core.PVector; /** * This class handles loading and playing images in a series as an animation, * like and animated gif, but not a gif. */ public class Animation extends DynamicSceneImage { // the number of milliseconds to show each image public int imageTime; public int imageTimer; private int elapsedTime; /** * All the images for this animation. */ private CircularList images; public Animation() { super(); images = new CircularList(); imageTime = 720; imageTimer = 0; elapsedTime = 0; } public Animation(String filePrefix, String fileSufix, int size, int digits) { this(); loadImages(filePrefix, fileSufix, size, digits); } public Animation(String filePrefix, String fileSufix, int size, int digits, DynamicSceneImage other) { super(other); images = new CircularList(); imageTime = 720; elapsedTime = 0; imageTimer = 0; loadImages(filePrefix, fileSufix, size, digits); updateScale(); } /** * Load images for this animation. * @param filePrefix The part of the filename before we start fudging it with numbers. * @param fileSuffix The end of the filename after we've fudged it with numbers. * @param size The number of images to load in the series. * @param digits The number of digits we'll look at for loading the image. */ public void loadImages(String filePrefix, String fileSufix, int size, int digits) { images.clear(); // load each image for (int i = 0; i < size; i++) { // use nf to add 0's to image number String fileName = filePrefix + PApplet.nf(i, digits) + fileSufix; PImage newImage = Util.applet.loadImage(fileName); if (newImage != null) { images.add(newImage); Util.logInfo("Loaded Image: " + fileName); } else { Util.logErr("Failed to load image: " + fileName); } } // queue up the first image image = images.current(); } /** * Updates the current image it it's time. */ @Override public void update(int deltaTime) { super.update(deltaTime); imageTimer += deltaTime; if (imageTimer >= imageTime) { // enough time has passed to show the next image images.next(); image = images.current(); updateScale(); imageTimer = 0; } } }