|
-
July 2nd, 2001, 07:32 AM
#1
How can I add a Timer/Clock to my game?
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
-
July 2nd, 2001, 08:06 AM
#2
Re: How can I add a Timer/Clock to my game?
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 :-)))))
*******************************************
-
July 2nd, 2001, 08:52 AM
#3
Re: How can I add a Timer/Clock to my game?
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
[email protected]
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
-
July 2nd, 2001, 11:05 AM
#4
Re: How can I add a Timer/Clock to my game?
How can I attach this code to a button?
Thanks
Mark
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|