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

2014/1/16

how to add object when hovering over actor??

0868626 0868626

2014/1/16

#
Hello dear Greenfooters i'm new here and nice to meet you all i have a question: i am making a menu for 4 different games, so i made a map with four different objects in it , now i want to add an option so when you hover with your mouse over an object it will add another object that describes the mini-game , this is my code so far , i hope anyone can help me out here
public void act()  
    {  
        anm();

        if (Greenfoot.mouseMoved(this))
        {   
            getWorld().addObject(new describeGame(), 250, 530);       
        }
        else
        {
            // remove the first object(describe game)
        }
}
sorry for my poor english
danpost danpost

2014/1/16

#
Hovering requires a two part condition to begin an action (for when the mouse moves from not on to on the object) and a three part condition to end it (for when the mouse moves from on to not on the object). Basically, the moving on part is (in pseudo-code) 'if was last not on and on now, then begin action' and the moving off part is 'if was last on and now not on, then end action'. The second part looks like only two, but it is two parts just to check if not on (to check if moving off, you need to know that the mouse has moved at all and that it did not move over the object). My Fps Actor Class scenario has an example of hovering.
0868626 0868626

2014/1/16

#
thanks man it works now.
You need to login to post a reply.