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

2019/5/20

Game starts instantly when I hit enter before I press the "Run" button

EMRX EMRX

2019/5/20

#
Hello, I want to have a StartScreen. It works, but there is a problem though. When I press the "Run" button and hit enter, the game begins and everything works well. The problem is when I hit the enter key before running the game with the "Run" button. In this case, the game instantly starts when pressing the "Run" button. How can I prevent this?
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class StartScreen here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class StartScreen extends World
{

    /**
     * Constructor for objects of class StartScreen.
     * 
     */
    public StartScreen()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1000, 900, 1); 
    }
    public void act()
    {
        if(Greenfoot.isKeyDown("enter"))
        {
            Greenfoot.setWorld(new Hintergrund());
        }
    }
}
danpost danpost

2019/5/20

#
In this case, you can use:
if ("enter".equals(Greenfoot.getKey()))
You need to login to post a reply.