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 › Animated Images and Calling them later on
Page Index Toggle Pages: 1
Animated Images and Calling them later on? (Read 1262 times)
Animated Images and Calling them later on?
Sep 5th, 2007, 12:27am
 
Alright, heres the situation.  I have a few .gif images that I can't seem to get processing to animate without having to manually use this code every time I want to use one:


int numFrames = 14;  
int frame = 0;
PImage[] images = new PImage[numFrames];
   
void setup()
{
 size(500, 300);
 background(255);
 frameRate(19);

 
 images[0]  = loadImage("twelvestance1.jpg");
 images[1]  = loadImage("twelvestance2.jpg");
 images[2]  = loadImage("twelvestance3.jpg");
 images[3]  = loadImage("twelvestance4.jpg");
 images[4]  = loadImage("twelvestance5.jpg");
 images[5]  = loadImage("twelvestance6.jpg");
 images[6]  = loadImage("twelvestance7.jpg");
 images[7]  = loadImage("twelvestance8.jpg");
 images[8]  = loadImage("twelvestance9.jpg");
 images[9]  = loadImage("twelvestance10.jpg");
 images[10] = loadImage("twelvestance11.jpg");
 images[11] = loadImage("twelvestance12.jpg");
 images[12] = loadImage("twelvestance13.jpg");
 images[13] = loadImage("twelvestance14.jpg");
 

}

void draw()
{
 frame = (frame+1)%numFrames;
 image(images[frame], 40, 180);
}

What I'm looking for is a way to make these animations into a function to call on later, like if I press the letter B, then pull up animation1. Either that, or to have processing know how to animate a .gif and make my life easier :)

It's eventually going to be somewhat of a game, where the characters punch, etc. and I know there has to be a shorter way than manually retyping the code to get an animation for a specific key.  How can I accomplish this in processing?
Re: Animated Images and Calling them later on?
Reply #1 - Sep 5th, 2007, 1:25am
 
Code:


Animation anim,anim2;
void setup()
{
size(500, 300);
background(255);
frameRate(19);
anim = new Animation("twelvestance","jpg",14);
anim2 = new Animation("twelvestance","jpg",4);
}

void draw()
{
background(0);
anim.draw(mouseX,mouseY);
anim2.draw(mouseX-50,mouseY+50);
}

class Animation
{

int numFrames;
int frame;
PImage[] images;

Animation(String imagename, String, extension, int frames)
{
numFrames = frames;
images = new PImage[numFrames];
for(int i = 0; i < images.length; i++){
images[i] = loadImage(imagename+(i+1)+"."+extension);
}
}

void draw(int x, int y)
{
frame = (frame+1)%numFrames;
image(images[frame], x, y);
}
}



or something
Re: Animated Images and Calling them later on?
Reply #2 - Sep 6th, 2007, 2:05pm
 
Thanks a lot.  the code seems to work, excpet that I get an error at this line...

   
Animation(String imagename, String, extension, int frames)

It tells me that its "expecting IDENT,found','"   at the first parentheses. I don't see the problem Sad  

Thank you for your reply though, I really appreciate it.
Re: Animated Images and Calling them later on?
Reply #3 - Sep 6th, 2007, 2:17pm
 
Animation(String imagename, String, extension, int frames)

String, extension  <-- there is a ',' that should not be there..

replace by

Animation( String imagename, String extension, int frames )


error msgs sometimes are a pain in the a** but most of the time they are helpful
Re: Animated Images and Calling them later on?
Reply #4 - Sep 7th, 2007, 2:37am
 
D'oh (>_<)
Thank you for pointing that out.  I feel like I just scrolled my eyes through that thing without looking at the punctuation/capitalization.  It works Smiley  Thanks.
Page Index Toggle Pages: 1