Hello everyone. I’m coding a GUI for a schoolproject, where i need to register whether or not the user has clicked on the right button or not. I’ve made different hitboxes on the screen where the clicks will be true, but when I use more than one. I only get a message that there have been misclicks? What to do?
This is my current code, and i apologize in advance if it has not been formatted correctly within the forums guidelines, I’m new here hehe
PImage img;
Widget b1 = new Widget(20, 843, 32, 30);
Widget b2 = new Widget(77, 843, 32, 30);
Widget b3 = new Widget(132, 843, 32, 30);
Widget b4 = new Widget(189, 843, 32, 30);
Widget b5 = new Widget(242, 843, 30, 30);
Widget b6 = new Widget(273, 829, 44, 30);
Widget b7 = new Widget(273, 860, 44, 30);
Widget b8 = new Widget(338, 843, 32, 30);
Widget b9 = new Widget(393, 843, 32, 30);
Widget b10 = new Widget(449, 843, 32, 30);
Widget b11 = new Widget(512, 843, 32, 27);
Widget b12 = new Widget(512, 820, 32, 22);
Widget b13 = new Widget(512, 871, 32, 20);
Widget b14 = new Widget(600, 843, 44, 30);
void setup() {
size(559, 900);
img = loadImage("GPS.jpg");
}
void draw() {
image(img, 0, 0, width, height);
b1.display();
b1.buttonClicked();
b2.display();
b2.buttonClicked();
b3.display();
b3.buttonClicked();
b4.display();
b4.buttonClicked();
b5.display();
b5.buttonClicked();
b6.display();
b6.buttonClicked();
b7.display();
b7.buttonClicked();
b8.display();
b8.buttonClicked();
b9.display();
b9.buttonClicked();
b10.display();
b10.buttonClicked();
b11.display();
b11.buttonClicked();
b12.display();
b12.buttonClicked();
b13.display();
b13.buttonClicked();
b14.display();
b14.buttonClicked();
}
class Widget {
int posX, posY, Rectwidth, Rectheight;
String Laple;
Widget(int posx, int posy, int rectwidth, int rectheight) {
posX = posx;
posY = posy;
Rectwidth = rectwidth;
Rectheight = rectheight;
}
void display() {
//firekant
stroke(255);
strokeWeight(0);
fill(255, 50);
rectMode(CORNER);
rect(posX, posY, Rectwidth, Rectheight);
}
boolean buttonClicked() {
boolean Clicked = false;
if ((mouseX > posX && mouseX < posX + Rectwidth) && (mouseY > posY && mouseY < posY + Rectheight) && mousePressed) {
Clicked = true;
println("Knaptryk: "+mouseX+"x & "+mouseY+"y");
} else if (mousePressed) {
Clicked = false;
println("Misklik: "+mouseX+"x & "+mouseY+"y");
} else {
Clicked = false;
}
return Clicked;
}
}