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 › creating png animation through array
Page Index Toggle Pages: 1
creating png animation through array (Read 647 times)
creating png animation through array
Oct 14th, 2009, 6:08am
 
I´m trying to make a small animation for a game using 3 pngs and looping them through an array but I can´t seem to get it to work.

CODE:

int numFrames = 3;

PImage[] images = new PImage[numFrames];

void setup(){
 size(400, 400);
 frameRate(1);
 images[0] = loadImage("0.png");
 images[1] = loadImage("1.png");
 images[2] = loadImage("2.png");
}

void draw(){

for (int i = 0; i < images.length; i++){
image(images[i], 0,0,100,100);
loop();
}


All the pics load on top of each other instead of one at a time. Any help is appriciated ^^
Re: creating png animation through array
Reply #1 - Oct 14th, 2009, 7:01am
 
Some problems:
- In draw(), you load again the images (a bad idea... Smiley).
- In draw(), you don't display the images...
- And why do you use loop()?
- When you get an error, please try and show the exact message... Smiley I don't understand the one you report.

And a hint:
Don't loop in draw(), increment a (global) counter (restarting at zero after numFrames) and display the current image. draw() is a kind of loop in itself.

[EDIT] You changed the code while I was typing the answer above... So you fixed some of the problems! Good. I leave the list as it is of general interest (common gotchas).
The hint is still usable... Cheesy
Re: creating png animation through array
Reply #2 - Oct 14th, 2009, 7:43am
 
I got it to work using sequencing Smiley thank you for the tips.


CODE:
frame = (frame+1) % numFrames;

that solved it Cheesy
Page Index Toggle Pages: 1