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

2016/10/21

Help! Press space once to start game

j.moseley99 j.moseley99

2016/10/21

#
if(Greenfoot.isKeyDown("space"))
        {
          move(-4);
        }
I'm making a version of Pong for a college project and I need help. I am fairly new to greenfoot and was wondering how to make the ball keep moving after pressing the space bar only once. My current code (above) requires you to hold the space bar down in order for the ball to move. I've tried searching the forums for an answer but I can't find one and I was hoping someone could help! Thank you.
Super_Hippo Super_Hippo

2016/10/21

#
If you just want it to start the game with it, you could use this in your world:
private boolean gameStarted = false;

public void act()
{
    while (!gameStarted)
    {
        if (Greenfoot.isKeyDown("space"))
        {
            gameStarted = true;
        }
    }
}
In the Ball class, you let it move without a condition.
You need to login to post a reply.