Timer in Greenfoot

1.1k Views Asked by At

I'm making a game right now and want to add a timer to count down to my end game screen, I can get the text to show up on my game screen but the numbers won't go down.

Link to code

Any feedback would help!

1

There are 1 best solutions below

0
the busybee On

Biased note: Greenfoot is a great tool to learn to program in Java. Keep going! But learn to read documentation[1], please.

You are calling subtractTime() only in the constructor Timer(). This way it will be called only once at creation time of your Timer object.

Call it in the act() method instead.

It will be called every time when the Greenfoot system lets all actors and the current world, well, act. The time between the calls is controlled by the "Speed" control below the world's frame, or by the specific methods of the class Greenfoot.

If you need "real-time" values like seconds, do some research how to obtain seconds or milliseconds.


[1]: You can read Greenfoot's documentation in the Editor window by double-clicking on "World" or "Actor" in the class diagram on the right.