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

2013/5/21

Can someone send mainmenu code to me?

Miikku Miikku

2013/5/21

#
Can someone send mainmenu code to me? Please
Gevater_Tod4711 Gevater_Tod4711

2013/5/21

#
What should be included main menu?
Miikku Miikku

2013/5/21

#
Start button, and instructions. I edit texts if you do only a code. Please.
Gevater_Tod4711 Gevater_Tod4711

2013/5/21

#
Do you mean a button for instructions or just the text?
Miikku Miikku

2013/5/21

#
Button
Gevater_Tod4711 Gevater_Tod4711

2013/5/21

#
Ok. Therefore you need to know the locations of the buttons to know whether they get clicked. The code you need is the following:
public class MainMenu extends Actor {
    private MouseInfo mouse;
    
    public void act() {
        mouse = Greenfoot.getMouseInfo();
        if (Greenfoot.mouseClicked(this) && mouse != null) {
            if (mouse.getX() > startX1 && mouse.getX() < startX2 && mouse.getY() > startY1 && mouse.getY() < startY2) {
                //instead of startX/Y you have to use the coordinates of the buttons;
               //X1 is the left x coordinate of the button, X2 is the right, Y1 is the top y coordinate and Y2 the bottom y coordinate;
                //start the game;
            }
            if (mouse.getX() > instrX1 && mouse.getX() < instrX2 && mouse.getY() > instrY1 && mouse.getY() < instrY2) {
                getWorld().addObject(new Instruction(), getWorld().getWidth()/2, getWorld().getWidth()/2);
                 //the instructions also should have a button to return to the main menu. Therefore you can use the same code as in this class.
            }
        }
    }
}
To get the coordinates of your buttons you can use Photoshop, Paint, ... Or you use Greenfoot and print the coordinates on the screen. Therefore you need to add this code:
//...
if (Greenfoot.mouseClicked(this) && mouse != null) {
    //...
    System.out.println(mouse.getX() + " " + mouse.getY());
    //this will show the current mouse coordinates when you click on the main menu image.
}
Miikku Miikku

2013/5/21

#
Thanks!
You need to login to post a reply.