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 & HelpPrograms › Re: mousepreesed problems
Page Index Toggle Pages: 1
Re: mousepreesed problems (Read 538 times)
Re: mousepreesed problems
Apr 21st, 2010, 5:02am
 
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;
Page Index Toggle Pages: 1