Using mousePressed() as a function

If you only want the counter to increase once for each click, instead of continuing to increase while you have the mouse button pressed, you can use mousePressed as a function

(Same set of images as the last example)

/* mousePressed() click Flipbook */ PImage zero; PImage one; PImage two; PImage three; PImage four; PImage five; int counter=0; void setup() { size(640,480); zero = loadImage("zero.jpg"); one = loadImage("one.jpg"); two = loadImage("two.jpg"); three = loadImage("three.jpg"); four = loadImage("four.jpg"); five = loadImage("five.jpg"); } void mousePressed() { counter++; if (counter>5) counter=0; } void draw() { if (counter == 0) { image(zero,0,0); } if (counter ==1) { image(one,0,0); } if (counter==2) { image(two,0,0); } if (counter==3) { image(three,0,0); } if (counter==4) { image(four,0,0); } if (counter==5) { image(five,0,0); } }