This site requires JavaScript, please enable it in your browser!
Greenfoot back
Finn.C
Finn.C wrote ...

2019/11/10

How can I make a object change color when the mouse is on it?

Finn.C Finn.C

2019/11/10

#
So I was tryint to make a title screen for a game and wanted to allow to player to see what option they have selected. This is my Code:
public class Controls extends Actor
{
    GreenfootImage Controls;
    GreenfootImage Red_Controls;
    public void act() 
    {
         if (Greenfoot.mouseClicked(this))
         {
           Greenfoot.setWorld(new controlls());  
         }
         if (Greenfoot.mouseMoved(this))
         {
             setImage(Red_Controls);
         }
         else if(Greenfoot.mouseMoved(this)==false)
         {
             setImage(Controls);
         }
    } 
    public Controls()
    {
       Controls = new GreenfootImage("Controls.png");
       Red_Controls= new GreenfootImage("Red_Controls.png");
    }
}
Thanks!
danpost danpost

2019/11/10

#
The condition on line 15 will be true-- that is, the mouse will not be detected as moving on this object unless the mouse is moved on this object. To clarify, t will not be detected as moving on this object if the the mouse is ON the object, but does NOT move. Only change back to normal image BOTH when mouse moves, AND NOT on this object:
if (Greenfoot.mouseMoved(null) && ! Greenfoot.mouseMoved(this))
You need to login to post a reply.