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

3 days ago

Clicking anywhere on the screen to start code using Greenfoot.mouseClicked

charmanderr charmanderr

3 days ago

#
How do I use if(Greenfoot.mouseClicked(para)) to have the user start the game when they click anywhere on the screen? This is for an assignment, and the user is prompted to start the game. I've set the Background to an image, and put (this) into the parameters, and then called a method that I already wrote out.
super(1271, 712, 1); 
        setBackground("start.jpg");
        if (Greenfoot.mouseClicked(this))
        {
            started();
        }
danpost danpost

3 days ago

#
charmanderr wrote...
How do I use if(Greenfoot.mouseClicked(para)) to have the user start the game when they click anywhere on the screen? This is for an assignment, and the user is prompted to start the game. I've set the Background to an image, and put (this) into the parameters, and then called a method that I already wrote out. << Code Omitted >>
The code you are showing is only executed when that particular world is created. It does not run when you click on the "Step" or "Run" buttons. The code (lines 3 through 6) needs to be in the act method or a method initiated through the execution of the act method.
You need to login to post a reply.