I have a simple code that populates in my menu (showing a certain text), and when key ("space") is pressed it gets removed... but how could I make it so that if ("space") is pressed again, the text shows again.
Making so that When game begins, instructions should appear on the screen and stay on the screen until the user presses the spacebar. If the user presses the space bar again, the instructions should re-appear.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public class GameInstructions extends Actor { /** * Act - do whatever the GameInstructions wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { //setImage(new GreenfootImage("Use/hold UP arrow key to prevent hitting any obstacles, ENJOY!",30, Color.WHITE, Color.BLACK)); show(); } public void show() { setImage( new GreenfootImage( "Use/hold UP arrow key to prevent hitting any obstacles, ENJOY!" , 30 , Color.WHITE, Color.BLACK)); if (Greenfoot.isKeyDown( "space" )) { getWorld().removeObject( this ); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public class Menu extends World { static int xDimension = 800 ; static int yDimension = 600 ; GameInstructions instruc = new GameInstructions(); /** * Constructor for objects of class Menu. * */ public Menu() { // Create a new world with 800x600 cells with a cell size of 1x1 pixels. super (xDimension, yDimension, 1 , false ); setPaintOrder (GameInstructions. class , Play. class ); addObject( new Play(), xDimension/ 2 , yDimension/ 2 ); addObject(instruc, 397 , 388 ); |