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

2017/5/28

Start screen not working

SebiRaul SebiRaul

2017/5/28

#
Hello, I am trying to make a start screen for my project and i want to click anywhere on it and then go to another screen, but it's not working.
import greenfoot.*;
public class StartScr extends World
{
    public StartScr()
    {    
        super(600, 400, 1); 
        if(Greenfoot.mouseClicked(this))
        {
            Greenfoot.setWorld(new StartScreen2());
        }
    }
}
It worked a few hours ago, but now, I don't know what's happening.
danpost danpost

2017/5/28

#
The constructor (lines 4 through 11) is only executed once per object created from the StartScr class. It cannot continuously check for a mouse click like the act method can. Change the class to:
import greenfoot.*;

public class StartScr extends World
{
    public StartScr()
    {    
        super(600, 400, 1); 
    }
    
    public void act()
    {
        if(Greenfoot.mouseClicked(this))
        {
            Greenfoot.setWorld(new StartScreen2());
        }
    }
}
SebiRaul SebiRaul

2017/5/28

#
Aah, I completely forgot about the act method. Thank you so much :D.
You need to login to post a reply.