We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Animation using mouseX
Page Index Toggle Pages: 1
Animation using mouseX? (Read 544 times)
Animation using mouseX?
Dec 9th, 2007, 8:58am
 
I want to create an animation where the frames increase as the value of mouseX increases. I'm able to load images and animate them in the draw function, but I have no idea how to apply the mouseX value to this. Any help would be greatly appreciated.
Re: Animation using mouseX?
Reply #1 - Dec 9th, 2007, 9:37am
 
if your animation is an array of images, then it is easy :

Code:
// init the array of images
PImage[] frames = new PImage[100];

void setup() {
// load the images here. example:
for (int i = 0; i < frames.length; i++) {
frames[i] = loadImage("img" + i + ".jpg");
}
}

void draw() {
// choose a frame to display depending on mouseX
image(frames[constrain(mouseX, 0, 99)], 0, 0);
}
Re: Animation using mouseX?
Reply #2 - Dec 9th, 2007, 9:44pm
 
Thank you!
Page Index Toggle Pages: 1