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

2013/5/23

Menu with a button

JesusJesus JesusJesus

2013/5/23

#
Hey, in my game i made a menu with a button. When the button was clicked with the mouse it should Change the World and start the game, but nothing happens.... What have i done wrong?? This is the world class of the menu (home):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public Home()
    {   
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1);
        prepare();
    }
    private void prepare()
    {
        Button button = new Button();
        addObject(button, 420, 300);
        return;
    }
    public void act()
    {
        if (Greenfoot.mouseClicked(Button.class))
        {
            Greenfoot.setWorld(new Map());
        }
    }
Thank you very much.
Gevater_Tod4711 Gevater_Tod4711

2013/5/23

#
The method mouseClicked doesn't need a class as parameter but an object. If you put the act method into the Button class and change the mouseClicked(Button.class) to mouseClicked(this) it'll work.
JesusJesus JesusJesus

2013/5/23

#
Thank you for your reply, but it still not working. Ive copied the act method completly into the button class, and removed it in the home class, but if i start the game and click on the button ... nothing happens. But why?! Maybe you have another idea? or is it maybe because of another class? (PS: Sry for my English ;) )
JesusJesus JesusJesus

2013/5/23

#
OOOOh im very sorry i forgot to Change the button.class into this, now it works. Thank you very much, i will follow you now :)
JesusJesus JesusJesus

2013/5/23

#
Ach jetzt sehe ich erst durch deinen namen dass du deutsch bist^^ das hätte es für mich leichter gemacht naja egal ;)
You need to login to post a reply.