i'm making a game and i want to add text into the game so when it goes to the game over screen there will be text that the player can click on in order to rest the game and continue playing
public class SimpleActor extends greenfoot.Actor {}// a field to hold the actor
private Actor resetActor;
// a game over method with the following to apply the reset actor
GreenfootImage resetText = new GreenfootImage("Click here to play again", 48, Color.BLACK, new Color(0, 0, 0, 0));
GreenfootImage resetImage = new GreenfootImage(resetText.getWidth()+30, resetText.getWidth()+20);
resetImage.setColor(Color.RED);
resetImage.fill();
resetImage.setColor(Color.LIGHT_GRAY);
resetImg.fillRect(3, 2, resetImage.getWidth()-6, resetImage.getHeight()-4);
resetImage.drawImage(resetText, 15, 10);
resetActor = new SimpleActor();
resetActor.setImage(resetImage);
addObject(resetActor, getWidth()/2, getHeight()/2);
// and finally, in act method
if (resetActor != null && Greenfoot.mouseClicked(resetActor)) Greenfoot.setWorld(new MyWorld());public class Text extends Actor
{
public void act()
{
GreenfootImage resetText = new GreenfootImage("Play again", 48, Color.BLACK, new Color(0, 0, 0, 0));
if(Greenfoot.mouseClicked(resetText))
{
Greenfoot.setWorld(new Start());
}
}
}
public class GameOver extends World
{
public GameOver()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(900, 600, 1);
Add();
}
public void Add()
{
Text text = new Text();
addObject(text,450,450);
}
}public class Text extends Actor
{
public Text()
{
GreenfootImage resetText = new GreenfootImage("Play again", 48, Color.BLACK, new Color(0, 0, 0, 0));
setImage(resetText);
}
public void act()
{
if (Greenfoot.mouseClicked(this)) Greenfoot.setWorld(new Start());
}
}