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

2013/4/6

How would I make a title screen?

BubbaB BubbaB

2013/4/6

#
It's something that I have been thinking about for a while. I probably would want to create another world object, but how do I set the title screen world object to be used when the program starts, then stop, then have the actual game world start immediately after that? I'm just curious. Thanks!
Gevater_Tod4711 Gevater_Tod4711

2013/4/6

#
One way to do this would be a new world subclass. Another way would be just to add a main menu. In both cases you have to check whether the starting button or key is pressed if you want to start the gamem. (To check for a key you should use Greenfoot.getKey(String keyname) and for a button you can click with the mouse you should use the mouseInfo class of Greenfoot). If this button or key is pressed you have to start the game either with a starting method (when you use the main menu) or with the Greenfoot.setWorld(World world) method if you use two worlds. If you want your main menu or starting screen to come up every time the game is started you just have to add this in the world constructor: addObject(new MainMenu(), getWidth()/2, getHeight()2); (this will add a main menu in the middle of the screen). Or you can just create a new world if you are using the two worlds. If you set the world using the mouse in your scenario and so manualy set the world this world that you created will be the first world that comes up every time you open the scenario.
HungryHide HungryHide

2016/12/9

#
@Gevater_Tod4711 do you have code for that?
danpost danpost

2016/12/9

#
If you want the title screen to remain for a few seconds after the project is started, then add an int field to count act cycles. In the act method, increment it and check its value for something like 200, where it will set the game active:
import greenfoot.*;

public class TitleScreen extends World
{
    private int counter;

    public TitleScreen()
    {
        super(600, 400, 1);
    }

    public void act()
    {
        if (++counter == 200) Greenfoot.setWorld(new GameWorld());
    }
}
HungryHide HungryHide

2016/12/9

#
Well it's not that I want the title screen to be removed after a certain period of time, rather I want the title screen to have a set of instructions on it and when the player is ready to move on, they have the option to press the space key whenever they choose to do so. So basically making it manual.
Nosson1459 Nosson1459

2016/12/9

#
You could do this: Make a world subclass like this:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

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

    /**
     * Constructor for objects of class TitleScreen.
     * 
     */
    public TitleScreen()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        Greenfoot.start();
    }
    public void act()
    {
        if (Greenfoot.isKeyDown("space")) Greenfoot.setWorld(new MainWorld());
    }
}
Then right-click on TitleScreen in the side bar of Greenfoot and in the drop down menu click on "new TitleScreen()" so that TitleScreen is initialized first.
WillyRed WillyRed

2016/12/9

#
Yes also you can use if(Greenfoot.isMouseClick(This()) and that what do the same thing with the same coad he said Greenfoot.setWorld(new MainWorld()) this would allow you to make a start button.
danpost danpost

2016/12/9

#
WillyRed wrote...
Yes also you can use if(Greenfoot.isMouseClick(This()) and that what do the same thing with the same coad he said Greenfoot.setWorld(new MainWorld()) this would allow you to make a start button.
@WillyRed, I cannot find the 'isMouseClick' method in the Greenfoot class. Nor can I find any method called 'This'. My point is that you need to show precise code. Most users are beginners and will get more confused when suggestions such as this are given. I am sure you meant:
if (Greenfoot.mouseClicked(this))
but, others may not know that.
You need to login to post a reply.