So i'm creating a tile based game and currently working on hovering on tiles i have the hovering sorted so that when you hover over an image it changes colour but i am stuck with how to remove the colour when the next tile is hovered upon.
Tile previous;
public void CheckHover() {
for (Tile t : map.getTiles()) {
if (t.IsMouseOver(screen.getMousePosition().x, screen.getMousePosition().y)) {
t.setMouseOver(true);
if (previous == null) {
previous = t;
} else {
previous.setMouseOver(false);
}
}
}
}
My code above does not quite work i believe it may be down to how i am referencing the object but if i am doing a for each loop how can i get object that is currently hovered and setMouseOver to false?