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

2019/6/2

Making a back button in Menu

gacha321 gacha321

2019/6/2

#
Hello, can anyone help me in my farm game :(( I just want to make a menu that include buy button, sell button, and look our animals and plants button. the problem is, when I have finished making a menu board for 3 list (buy, sell and look). I used mouse clicked to choose one of them, for example I choosed buy button to buy plants. but when I clicked the button, the list of plants became collided with the previous 3 lists (buy, sell and look). and how can if i finished use the menu that I can back to my game (FarmWorld). can anyone help me? :(( I'm sorry my english is bad because I'm from Indonesia. Here's My code 1. Here's for first menu when I touching the garden
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class Board1 extends World
{
 
    /**
     * Constructor for objects of class Board1.
     *
     */
    public Board1()
    {   
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(595, 535, 1);
        showText("====Garden===", 295, 90);
        showText("Buy", 250, 190);
        showText("Sell", 250, 310);
        showText("Look", 250, 435);
        prepare();
    }
}
2. and here's the code for buying plants.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class List2 extends Button
{
    /**
     * Act - do whatever the List2 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        // Add your action code here.
        if(Greenfoot.mouseClicked(this)){
        Greenfoot.setWorld(new Buy Plant());
        /*this what's makes collided with menu before because I can't remove the Board1 :(( */
        }
    }   
}
can anyone help me pls T^T. this is my homework and I can't do anythingg And how can that I can back play my game when I used the menu because there's no back buttons (I didn't know how to use) :(
danpost danpost

2019/6/2

#
Work on one thing at a time. The more general thing here is getting back to previous worlds. Need garden detection code that triggers a Board1 world to appear.
gacha321 gacha321

2019/6/2

#
ah I see, can I use de remove World? and how if this will delete my gold status??
danpost danpost

2019/6/2

#
gacha321 wrote...
ah I see, can I use de remove World? and how if this will delete my gold status??
There is no remove World -- only a setWorld. You need to keep a reference to the old world in the new one so you can go back to it.
You need to login to post a reply.