I want to change my title image to the main world image when E is pressed. When I compile there are no syntax errors but when I run it doesnt work. Here is the code:
import greenfoot.*;
import java.awt.Color;
/**
* Write a description of class world here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class world extends World
{
/**
* Constructor for objects of class world.
*
*/
public world()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(500, 500, 1);
setBackground(new GreenfootImage("Title screen.png"));
if(Greenfoot.isKeyDown("e"))
setBackground(new GreenfootImage("moze.png"));
prepare();
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void prepare()
{
Mazer mazer = new Mazer();
if(Greenfoot.isKeyDown("e"))
{addObject(mazer, 1, 1);
mazer.setLocation(240, 13);}
Griever griever = new Griever();
if(Greenfoot.isKeyDown("e"))
addObject(griever, 15, 18);
}
}
