silen wrote on Apr 21st, 2010, 3:27am:hthis code has something wrong with it.
Indeed, but if you described more precisely what problem you see, maybe we could help you better.
I see problems, minor and major, but they might not be those you see...
Little fixes:
Code:PImage[] images = new PImage[3];
int j=0;
void setup (){
size (600,773);
for ( int i = 0; i< images.length; i++ )
{
images[i] = loadImage( i + ".jpg" );}
background(images[j]);
}
void draw(){
background(images[j]);}
void mousePressed(){
if (j<images.length - 1){
j++;}else{
j=0;}
Note: I don't want to question your style choice, but most programmers are lost by these closing braces at end of line, as their eye isn't trained to search them there.
I first thought the background() call in setup() was in the for loop...
It was the minor problem mentioned above, which thus doesn't exist...
The other fix was about j, going well beyond the limit of the array.
Note you can also write:
j = ++j % images.length;