Click to See Complete Forum and Search --> : How can I add a Timer/Clock to my game?
Mark1
July 2nd, 2001, 07:32 AM
Hi,
I have completed a game and it works well.
There is one more part to my game, that is, to add a clock (Timer) to it, so that when the game starts I can activate the timer, and when it finished I can deactivate it, and record the time taken.
The object is to complete the game/level in the fastest time, so I would also like to be able to record the timer.
Can anyone give me any info on code for this task.
Thanks
Mark
Gabriel Fleseriu
July 2nd, 2001, 08:06 AM
You can use the Date function. This returns a Variant/Date corresponding to the cuurent time and date. There also is a function named DateDiff. This computes the difference between two dates. You can customize the interval length to, say, seconds.
Enjoy,
Gabreil
*******************************************
Thank you in advance for rating my answer :-)))))
*******************************************
Cakkie
July 2nd, 2001, 08:52 AM
You can use the GetTickCount API to get something. I believe it gives the number of milliseconds since the system was started or so. Get the value at the beginning of the level, and at the end. Then just substract them and you have the time ellapsed in milliseconds.
private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () as Long
Dim StartTime as long
Dim EndTime as long
private Sub StartLevel()
StartTime = getTickCount
End Sub
private Sub EndLevel()
EndTime = GetTickCount
Msgbox "It took you " & Round((EndTime - StartTime)/1000,2) & " seconds to complete the level"
End Sub
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
Mark1
July 2nd, 2001, 11:05 AM
How can I attach this code to a button?
Thanks
Mark
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.