I tried to create the counter on this way now, but my timer just subtracts 1 second and then stops.
I have to hand out this project in three hours and I am slowly in despair.
public class Level2 extends MyWorld
{
Text timerText = new Text();
private int timer = 15;
/**
* Level2 enthält einen Timer, der 15 Sekunden abzählt.
* Wenn Zähler = 0 und Punktestand nicht 10, dann "Defeat"
*/
public Level2()
{
prepare(); // Level2 wird mit den gleichen Actors aus MyWorld bevölkert
}
private void prepare()
{
addObject(timerText, 730 , 40);
updateImage();
timerText.setText("Time: " + timer);
}
public void updateImage()
{
if (timer>0)
{
timer--;
if(timer%15==0)
{
timerText.setText("Time: " + timer);
updateImage();
} }
}
}public class Text extends Actor
{
// Der Timer startet bei 15 Sekunden
private static final Color transparent = new Color(0,0,0,0);
/**
*
*/
public Text()
{
this(" ");
}
public Text(String text)
{
setText(text);
}
public void setText(String text)
{
setImage(new GreenfootImage(text, 30, Color.BLACK, transparent));
}
}


