-1

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!

the busybee
  • 10,755
  • 3
  • 13
  • 30
  • Welcome to Stack Overflow. Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then [edit] your question to include the source code you have as a [mcve], which can be compiled and tested by others. Also check the [help/on-topic] to see what questions you can ask. Please see: [Why is “Can someone help me?” not an actual question?](http://meta.stackoverflow.com/q/284236). – Progman May 14 '20 at 21:41
  • You should always put your actual code in your question, not an image of it or a offsite link to it. – Gary May 14 '20 at 21:44
  • You probably want to redraw the image after decrementing the timer. Also you only seem to decrement it once, in the constructor, and then never again. – Roddy of the Frozen Peas May 15 '20 at 09:15

1 Answers1

0

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.

the busybee
  • 10,755
  • 3
  • 13
  • 30