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


1 2 3 4 5 6 7 | public void act() { if (Greenfoot.mousePressed( this )) { Greenfoot.setWorld( new WorldNameOfTheNextWorld()); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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 ()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 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 ); } |