i want to start a timer when my game starts, and then count down to zero and end the game. My problem that i can see the text in world, but my timer dont count down??
From world class
public class MyWorld extends World
{
private int timer = 6700;
Text timerText = new Text();
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
if (timer> 0)
{
timer--;
if(timer%60==0) timerText.setTexi t("Time left: " +(timer/60));
if(timer == 0) Greenfoot.stop();
}
//timeTimer();
addText();
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
//public void timeTimer()
//{
//if (timer>0)
// {
// timer--;
// if(timer == 0) Greenfoot.stop();
//}
//}
public void addText()
{
addObject(timerText, 100, 15);
timerText.setText("Time left: " + (timer/60));
}
}
From TEXT.CLASS
public class Text extends Actor
{
public Text()
{
this("Game over :(");
}
public Text(String text)
{
setText(text);
}
public void setText(String text)
{
setImage(new GreenfootImage(text, 24, Color.black, new Color(0, 0, 0, 0)));
}
}