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

2021/11/15

my main menu doesn't want to work

CodingCowgirl CodingCowgirl

2021/11/15

#
So, I’m creating a Greenfoot project which isn’t school-related for the first time ever. I’m still kinda a newbie here. Now my problem is that my main menu doesn’t run although the code seems to be correctly. (I followed a YouTube tutorial cause as I said newbie.) I can try to run act but nothing happens. Any tips here?
public class MainMenu extends World
{

    /**
     * Constructor for objects of class MainMenu.
     * 
     */
    public MainMenu()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1920, 1080, 1); 
         GreenfootImage bg = new GreenfootImage("london-background.png");
         bg.scale(getWidth(), getHeight());
         setBackground(bg);
         mainMenu();
    }
    
    private void mainMenu() {
        Logo logo = new Logo();
        addObject(logo, 1980, 1080);
    }
    
    public void act() {
         if(Greenfoot.isKeyDown("space")) {
            Greenfoot.setWorld(new playQuiz());
            }
    }
}
RcCookie RcCookie

2021/11/15

#
What exactly does "doesn't run" mean? Is the referenced image "london-background.png" present in your project files? Do you have the class "Logo" implemented?
CodingCowgirl CodingCowgirl

2021/11/15

#
@RcCookie It doesn't pop up like it should. So, the logo I designed doesn't appear
Gbasire Gbasire

2021/11/15

#
You should add your logo at the middle of the screen instead :
private void mainMenu() {
        Logo logo = new Logo();
        addObject(logo, 960, 540);
    }
CodingCowgirl CodingCowgirl

2021/11/16

#
@Gbasire Thank you.
CodingCowgirl CodingCowgirl

2021/11/16

#
@Gbasire Now it works perfectly. At least it appears. I just have to fix that it change the world when I press space.
You need to login to post a reply.