Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Having issues witht the TimerTask and creating a winning/losing screen..

+5 votes
Hello all,

I've looked into creating the Timer and it works fine with a println statement. Upon curiosity of trying to create the winning and losing screen using the LibGdx, I'm at a total loss. I know that I need to stop the rain sounds and the game and draw a screen that says you win/lose..

 

Any help is appreciated -- I also may stop by Stonedahl's office tomorrow..
asked Sep 6 in CSC 285 (F17) by Dylan Hart (100 points)

2 Answers

+1 vote

While you could use the java.util.Timer class, that uses multiple threads, which won't work with the HTML-deployment target, so you're better off sticking to the LibGDX library options.

The simplest option is just to use the TimeUtils class to record the time the game starts (in the constructor), and then measure how much time has passed (in the render() method, which gets called repeatedly by the game engine).

However, you could also look into LibGDX's Timer class which offers more sophisticated functionality.

In general, you may as well get used to researching answers for how to do things in LibGDX... e.g. by Googling "LibGDX timer count down" , and checking out the first few links to see if you can find something useful.  That's a big part of real-world software development, actually...

answered Sep 7 by Forrest Stonedahl (100 points)
–1 vote
Try looking at page 82 of the OOAD book. It creates a timer with a run method. Now my knowledge of the inner class is a little hazy, but I believe the run executes every delay, so if you want a variable to change or execute certain code, there would be the place. I also found scheduleAtFixedRate to be a lot easier to use because it specified a field to set the frequency, such as 1 second... or 1000 ms.
answered Sep 6 by Daniel Zwiener (100 points)
...