Last click and keeping the image

So I have a series of clicks setup, each click replaces the last image with the next one. When I get to the last image, I want it to stay even if there is an accidental click afterwards. Is there a way to do this?

1 Like

@bryan give you:

void mousePressed() {
  currentImage += 1;
  if (currentImage > 6) {
    currentImage = 0;
  }
}

but you could do:

void mousePressed() {
  currentImage++;
  if (currentImage > 6)    currentImage = 6;
}

or

void mousePressed() {
  currentImage++;
  currentImage =  constrain(currentImage,0,6);
}

2 Likes

Awesome! The last option worked perfectly! Do you know if there is a way I can now add clicks with new actions without that last image disappearing?

unclear what you want?

So if I click again, will I be able to create a new action or event, while still keeping that last image?

yes, there is a wide range of options, but you should think about a
better operation concept, even if it would mean to learn about GUI libs
( buttons, sliders… )
or play with this

but in any case, good style is:

void setup() {
  // ... the usual things you need here
  println("this is how it works:");
  println("mouse click change image 1 .. 6");
  println("mouse X makes THIS, mouse Y makes THAT ");
}
1 Like

the link proportioned by @kll is really useful. now, you have to understand what are you coding, and try to translate what are you requesting into pseudocode. For example:

so here, you want new actions when you are in the last image, and your last image will be the image 6. so you have to make something like
if (currentImage == 6){ image(flr, width/2, height/2); //now you immediately show what i'm guess some buttons so check the button examples in the processing page. //so inside of this statement you now have to add the new function that you want to display }
by the way, also look at how the switch function means, case currentImage when your currentImage variable is equal to 6, means if(currentImage == 6) .
so in the code you’ll have something like
case currentImage: image(flr6, 0, 0); switch(currentButton) { case 0: //functions and display of button0; break; case1: //functions and display of button1; break; }

1 Like