Just to revive this thread for future users; you can easily use the following as Menu:
And this as Start:
Since .getObjectsAt() returns a List, you can use "contains" to search for your particular item.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public class Menu extends World { private boolean init = false ; public Menu() { super ( 1000 , 600 , 1 ); setBackground( "Back.png" ); } public void started() { if (!init) { addObject( new Start(), 0 , 0 ); addObject( new TitleScreen(), 0 , 0 ); init = true ; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public class Start extends Actor { MouseInfo mouse; public void act() { mouse = Greenfoot.getMouseInfo(); if (mouse != null && getObjectsAt(mouse.getX(), mouse.getY(), Start. class ).contains( this )) { setImage( "Start/2.png" ); } else { setImage( "Start/1.png" ); } if (Greenfoot.mouseClicked( this )) { Greenfoot.setWorld( new Level1()); } } } |