|
-
Jun 3rd, 2002, 04:43 PM
#1
Thread Starter
Lively Member
gettickcount
Could someone show me how to use gettickcount, any declarations I need in modules, etc, and maybe an example? This is what I currently have, so maybe you can just tell me what is wrong. I DO have CheckMove in a loop, so thats not the problem.
LastPress is declared in a seperate module as a global integer. PC.(all that stuff) is in the same module as LastPress under a new type I made. Although it says Text1.Caption, its actually a label... I forget why I named it Text1. Nothing is wrong with the GetKeyState stuff, because before I put the gettickcount stuff in, it worked (but it went so fast it overflowed before my finger was off the button)
Sub CheckMove()
If LastPress > gettickcount Then
LastPress = gettickcount + 50
If GetKeyState(vbKeyUp) = 1 Then
PC.xvel = PC.xpos - PC.xview
PC.yvel = PC.ypos - PC.yview
PC.xpos = PC.xpos + PC.xvel
PC.ypos = PC.ypos + PC.yvel
frmGame.Text1.Caption = PC.xpos
End If
End If
End Sub
If you know whats wrong, please let me know.
Do you know if you will answer no to this question?
If we've never seen something happen, we can't know if its impossible.
If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
If someone orders you to disobey all of their orders, do you obey or disobey?
-
Jun 3rd, 2002, 05:26 PM
#2
Frenzied Member
I'm kinda sleepy so I might be wrong, but it should work ok if you replace the > with a < , and you declare LastPress like this: Static LastPress As Long (before the IF).
Hope that helped
-
Jun 3rd, 2002, 05:35 PM
#3
Thread Starter
Lively Member
Do you know if you will answer no to this question?
If we've never seen something happen, we can't know if its impossible.
If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
If someone orders you to disobey all of their orders, do you obey or disobey?
-
Jun 3rd, 2002, 05:41 PM
#4
Frenzied Member
Weird. Should work. Anyway, that's not the best way of doing things 
You're using a game loop, right? Then all you would have to do would be limiting the FPS, and checking for the key every loop cycle. Here's the code I use to limit the FPS (I put it right after the loop starts) :
VB Code:
'Slow down the FPS...
Do Until GetTickCount() >= LastTick + TicksPerFrame
DoEvents
Loop
LastTick = GetTickCount()
LastTick and TicksPerFrame are all Longs, declared before the loop starts. TicksPerFrame is the amount of miliseconds each frame lasts. Usually 30 is good for smooth animation
-
Jun 3rd, 2002, 06:21 PM
#5
Addicted Member
Use queryperformancecounter, not gettickcount. I'll post the code in a second.
Edit: Here you go...
VB Code:
Private CPUFreq As Currency
Public Sub InitTimer()
Dim cFreq As Currency
Call QueryPerformanceFrequency(cFreq)
CPUFreq = CDbl(cFreq)
End Sub
Public Function HiResTimer() As Double
Dim PCounter As Currency
Call QueryPerformanceCounter(PCounter)
HiResTimer = CDbl(PCounter) / CPUFreq
End Function
"1 4m 4 1337 #4xz0r!'
Janus
-
Jun 3rd, 2002, 06:37 PM
#6
Thread Starter
Lively Member
Above:I think I'll stick to tick counting for a while yet
Above above: Is this right? -
Code:
Sub Run()
Dim LastTick As Integer
LastTick = gettickcount + 50
Do Until gettickcount >= LastTick + 5
MobMoving
CheckMove
DoEvents
Loop
End Sub
Do you know if you will answer no to this question?
If we've never seen something happen, we can't know if its impossible.
If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
If someone orders you to disobey all of their orders, do you obey or disobey?
-
Jun 4th, 2002, 04:09 PM
#7
Thread Starter
Lively Member
Ahhh I finally got it running... You forgot to tell me how to declare gettickcount
Do you know if you will answer no to this question?
If we've never seen something happen, we can't know if its impossible.
If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
If someone orders you to disobey all of their orders, do you obey or disobey?
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
|