jeudi 24 mars 2016

JAVA - if statement not working, comparing values meet req, but action is not being performed

JAVA - I'm currently taking in the x and y position of the mouse and am comparing it to the location of a square. I checked the values of all that I was comparing and it should work. I also copy pasted so the code is the same in the if and in the S.O.P. I NEED HELP I'M LOSING MY MIND!

System.out.println(getMouseX());
System.out.println(getMouseY());
System.out.println();
System.out.println(Runner.squares.get(1).getX());
System.out.println(Runner.squares.get(1).getX() + Runner.squares.get(1).getWidth());
System.out.println();
System.out.println(Runner.squares.get(1).getY());
System.out.println(Runner.squares.get(1).getY() + Runner.squares.get(1).getWidth());

for (int i = 1; i < Runner.squares.size() - 1; i++) {
    if (getMouseX() >= Runner.squares.get(i).getX() && getMouseX() <= Runner.squares.get(1).getX() + Runner.squares.get(i).getWidth()) {
        if (getMouseY() >= Runner.squares.get(i).getY() && getMouseY() <= Runner.squares.get(1).getY() + Runner.squares.get(i).getWidth()) {
            System.out.println("removed");
            //Runner.squares.remove(i);

        }
    }
}

here is the console:

145
46

141
151.0

42
52.0

Aucun commentaire:

Enregistrer un commentaire