Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / How to properly use dbTimer

Author
Message
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 14th Aug 2011 14:58
Hey guys!
i want to make a last thing for my game.

So when the player reachs a pre-determined score, the game will rise the round.

What i want to do is when it rise the round, it make a
dbText at the center of the screen and it disappear after 2 seconds. Just to announce the round switch. and then call the "enemies"

I know how to make all, but i dont know how to use the dbTimer to set the 2 seconds to text disappear and start the round..

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 14th Aug 2011 15:24 Edited at: 14th Aug 2011 15:34
I dont use dbTimer sometimes it lets me down, but GetTickCount() from windows.h.

Didn't test it but you get the idea .



vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 14th Aug 2011 17:11
well it "worked"

It just displays on the screen for 1 milisecond.. xD

The 2000 is not working..

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
TerryRussell
13
Years of Service
User Offline
Joined: 11th Dec 2010
Location: Chichester, UK
Posted: 14th Aug 2011 20:29 Edited at: 14th Aug 2011 21:37
Here's how I do it. It has never let me down.

Just outside of the main loop, I set up some times:



Within the main loop, I check the times at different times, depending on what happens at what frequency:

For example:



Amazing Simulation
www.amazing-forum.com
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 14th Aug 2011 20:58
But.. how can i use it just to
check if it has been passed 2 seconds since the timer was activated
then if it isnt dbText

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
TerryRussell
13
Years of Service
User Offline
Joined: 11th Dec 2010
Location: Chichester, UK
Posted: 14th Aug 2011 21:40 Edited at: 16th Aug 2011 17:07
Just set the Timers[1]=dbTimer() at the start of your two seconds.


Then as your loop goes around, just check to see when 2 seconds have elapsed and then do whatever you need to do.



Amazing Simulation
www.amazing-forum.com
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 14th Aug 2011 22:33
May i see how you have used it?

I just tested my code, and it works perfectly.

Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 16th Aug 2011 00:14


I got this from a quick search http://www.cplusplus.com/reference/clibrary/ctime/clock/

Output:



Within the example is more than enough info to get you where you want to be. It uses clock(), but you can use GetTickCount() if you wish. The difference is that GetTickCount() gives you time from the start of your computer (up to ~40 days) and clock() gives you time from start of your program. Of course this is a countdown, but you see in the void wait ( int seconds ) function that the clock will give you time in milliseconds and you can convert your seconds to milliseconds to do a reference.

The fastest code is the code never written.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 16th Aug 2011 00:46 Edited at: 16th Aug 2011 01:56
i use my super accurate timer class (note that it MIGHT lose some very very tiny accuracy in pausing but generally, nothing to even bother thinking about), if anyone wants it:


usage is very easy:



and if you want to use a specific unit (minutes, hours, seconds, etc..)


also - if you will use some small unit, like microseconds or nanoseconds or whatever, make sure you change

to


because float will be too small to handle large numbers, and you won't need floating points in micro or nano seconds..

also one final note: the code may look messy or stupid, that's because it uses pImpl idiom, i really prefer to have my code written using it, especially when compiling as a .lib, but it's up to you, and you can do some minor changes to make it normal

EDIT: whoops, forgot some includes, added in the .h, i also forgot that you will need to call
at the beginning and
at the end of your program

Login to post a reply

Server time is: 2024-10-02 19:16:35
Your offset time is: 2024-10-02 19:16:35