ive finished my game off but i want to know how to add some sort of a game over showing the time that the player stayed alive
what would be the best way to show this and how can i achieve this?


//when the game ends: getWorld().removeObjects(getWorld().getObjects(null)); getWorld().addObject(new GameOver(), getWorld().getWidth()/2, getWorld().getHeight()/2); //if you put this code in a world subclass you have to delete the getWorld(). parts;
import greenfoot.*; import java.awt.Color; public class Clock extends Actor { private long startingTime; private boolean counting = false; public void act { if (counting) { displayTime(System.currentTimeMillis() - startingTime); } } private void displayTime(long time) { time /= 1000; int minutes = time / 60; int seconds = time % 60; String time = minutes + ":" + seconds; setImage(new GreenfootImage(time, 30, Color.black, new Color(0, 0, 0, 0))); } public void startClock() { counting = true; startingTime = System.currentTimeMillis(); } public String getTime() { time /= 1000; int minutes = time / 60; int seconds = time % 60; String time = minutes + ":" + seconds; return time; } }
Clock clock = new Clock(); getWorld().addObject(clock, 50, 30); clock.startClock();
if (!counting) return "0:0"; int time = (System.currentTimeMillis()-startingTime)/1000;