Animation animation1, animation2; float xpos, ypos; float drag = 80.0; void setup() { size(250, 220); colorMode (RGB, 100); frameRate(11); animation1 = new Animation("PT_Ama_", 33); animation2 = new Animation("PT_Pet_", 33); } void draw() { float difx = mouseX - xpos; if (abs(difx) > 1.0) { xpos = xpos + difx/drag; xpos = constrain(xpos, 30,70 ); } float dify = mouseY - ypos; if (abs(dify) > 1.0) { ypos = ypos + difx/drag; ypos = constrain(ypos, 10, 50); } // Display the sprite at the position xpos, ypos if (mousePressed) { animation1.display(xpos-animation1.getWidth()/8, ypos/4); } else { animation2.display(xpos-animation1.getHeight()/8, ypos/4); } } // 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) + ".jpg"; images[i] = loadImage(filename); } } void display(float xpos, float ypos) { frame = (frame+1) % imageCount; image(images[frame], xpos, ypos); rect (0, 0, width,height ); fill(238, 238, 238, (frame+1)); stroke(255); } int getWidth() { return images[0].width; } int getHeight() { return images[0].height; } }