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

2013/10/7

Simple Startup Graphic?

askgriff askgriff

2013/10/7

#
Okay, I'm looking for a way to do a simple startup graphic -- maybe a PNG Title Screen or something that will display until someone clicks or presses SPACE it moves on and runs the game.
danpost danpost

2013/10/7

#
There are several ways to accomplish this. The easiest way (with nothing but the 'super' call in the world constructor) is to have your world background as your title screen (this is the one thing that could be done in the constructor) and. when 'Run' is clicked on to start the scenario. reset the background and setup your game board using the 'started' method. The code could simply be:
public void started()
{
    if (getObjects(null).isEmpty())
    {
        setGameBackground(); // change background
        prepare(); // add actors
    }
}
The checking for no objects in the world prevents pausing and restarting the scenario from running the code in the method again. Another way is to create a separate World subclass for the title screen. It can check for click or keystroke (or run a timer; or any combination thereof) to set a new game world as the active world. You could use an Actor object, as well; but that gets a little more involved (could involve adding checks in multiple classes, shifting some code around in the world class, and more).
danpost danpost

2013/10/7

#
Actually, you could have some coding in the world constructor for those ways I said not to. You can initialize fields and set references to objects you create. Just do not add any actor objects into the world.
CreepingFuRbalL CreepingFuRbalL

2013/10/7

#
Hi im looking for a similar thing does anyone have a code for a main menu or title screen which they could give me only things i want on it are saying single player or multiplayer.
askgriff askgriff

2013/10/7

#
Thanks Danpost. What you're saying looks simply, but I'm not following. I know it's my fault because I'm relatively new to this stuff. You're saying to have a world background as my title screen and then when someone clicks "Run" it moves to a different "world"?
danpost danpost

2013/10/7

#
Correct, up to the point where you say 'it moves to a different "world". Make the initial background of your world the title screen image. Use the 'started' method (that is automatically called by the system when the scenario is started; or, in other worlds, when the 'Run' button is clicked on) to set the background image of the current world to your game play image (or just clear and fill it with Color.white; which should already be set as the drawing color for the background) and add the actor objects into the world. To clear and fill the background, use:
getBackground().clear();
getBackground().fill();
If that does not clear the background to a solid white color, then insert the following between the two lines above:
getBackground().setColor(java.awt.Color.white);
askgriff askgriff

2013/10/8

#
Danpost -- if you get a second could you look at this template and let me know how you would incorporate this method to add a startup screen? (http://www.greenfoot.org/scenarios/9522 )
danpost danpost

2013/10/8

#
Your world constructor should look like that below. And you should add the 'started' method.
public MyWorld() 
{
    super(640, 480, 1);
    // use the following or set the image as default for world
    setBackground(new GreenfootImage("titleScreenImageFilename.jpg"));
}

public void started()
{
    if (getObjects(null).isEmpty())
    {
        setBackground("road.png");
        prepare();
    }
}
You need to login to post a reply.