I would like to create a button so it says play, and when the user presses it, the game starts, and brings up the next screen / world
Thanks
public void act()
{
if (Greenfoot.mousePressed(this))
{
Greenfoot.setWorld(new WorldNameOfTheNextWorld());
}
}
import greenfoot.*;
public class Button extends Actor
{
/**
* Act - do whatever the Button wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
if (Greenfoot.mousePressed(this))
{
Greenfoot.setWorld (new LevelMenu ());
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* This class MenuWorld
*
* Jacqueline Reilly
* January 17, 2017
*/
public class MenuWorld extends World
{
/**
* Constructor for objects of class MenuWorld.
*
*/
public MenuWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
// Creating & adding menu object to world
addObject (new MenuGreeting ("Mr. Krabs vs Plankton"), getWidth ()/4, getHeight ()/4);
// Creating & adding play button to world
Button button = new Button ();
addObject (button, getWidth ()/2, getHeight ()/2);
}