Alright, here's the underlying issue I'm having. How can I tell if an object is being hovered over or clicked on by the mouse?
/** THE MENU WORLD CLASS */
import greenfoot.*;
public class Menu extends World
{
Actor buttonA, buttonB;
public Menu
{
super(600, 400, 1);
Button.mouseOn = null; // to clear any prior menu settings
addObject(buttonA = new Button("Previous", 120, 350);
addObject(buttonB = new Button("Next", 280, 350);
}
public void act()
{
if (Greenfoot.mouseClicked(buttonA))
{
// buttonA clicked codes here
}
if (Greenfoot.mouseClicked(buttonB))
{
// buttonB clicked codes here
}
}
}
/** THE BUTTON ACTOR CLASS */
import greenfoot.*;
public class Button extends Actor
{
public static Actor mouseOn;
public Button(String caption)
{
// create button image here
}
public void act()
{
// gaining mouse hover
if (mouseOn == null && Greenfoot.mouseMoved(this))
{
mouseOn = this;
// hover gained codes here
}
// losing mouse hover
if (mouseOn == this && Greenfoot.mouseMoved(null) && !Greenfoot.mouseMoved(this))
{
mouseOn = null;
// hover lost code here
}
}
}