So I'm trying to make a menu where a box appears around a button only when that button is hovered over. I have the following code...
helpButton and startButton are both Rectangles (a class I made). The issue is that after I hover over one of the buttons and the rectangle appears, it stays there permanently. Just as a note, I tested the execution sequence by adding a few System.out.println's and the code executes properly (if, else if, and else are all executed in an exepected manner). I can see that buttonMenu.clear() is being called. but no change is made to the image.
I've been stuck on this for hours! Please help!
getOwner().getBackground().drawImage(buttonMenu,
getOwner().getWidth()/2 - buttonMenu.getWidth()/2,
getOwner().getHeight()/2 - buttonMenu.getHeight()/2); //Draw button menu to World
MouseInfo info = Greenfoot.getMouseInfo();
if(info != null){
buttonMenu.setColor(java.awt.Color.RED);
if(startButton.contains(info.getX(), info.getY())){ //if start button is being hovered over
buttonMenu.drawRect(0, 0, startButton.getWidth()-1, startButton.getHeight()-1);
}
else if(helpButton.contains(info.getX(), info.getY())){ //help button is being hovered over
buttonMenu.drawRect(0, buttonMenu.getHeight()/2, helpButton.getWidth()-1, helpButton.getHeight()-1);
}
else buttonMenu.clear(); //if neither are being hovered over.
}
