Once you have arrays, you can use loops:
void mouseClicked() {
for (int i = 0; i < img.length; i++) {
img[i] = false;
}
if(mouseButton == LEFT){
img[7] = true;
}
else if(mouseButton == RIGHT){
img[0] = true;
}
}
although I am not sure why you do that...
Also, see patterns in numbers. Instead of:
if (img[0] == true) {
displayImage(0);
}
else if (img[1] == true) {
displayImage(-1024);
}
else if (img[2] == true) {
displayImage(-2048);
}
else if (img[3] == true) {
displayImage(-3072);
}
else if (img[4] == true) {
displayImage(-4096);
}
else if (img[5] == true) {
displayImage(-5120);
}
else if (img[6] == true) {
displayImage(-6144);
}
else if (img[7] == true) {
displayImage(-7168);
}
do:
for (int i = 0; i < img.length; i++) {
if (img[i]) { // No need for == true
displayImage(-1024 * i);
break; // Only one is true
}
}
To check a click on an image, you have to loop on them and check the bounds. There are plenty of examples in the samples and on the forum, and indeed a class can ease the work.