Results 1 to 7 of 7

Thread: gettickcount

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80

    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?

  2. #2
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80
    Nope, didn't work.
    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?

  4. #4
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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:
    1. 'Slow down the FPS...
    2.         Do Until GetTickCount() >= LastTick + TicksPerFrame
    3.             DoEvents
    4.         Loop
    5.         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
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  5. #5
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    Use queryperformancecounter, not gettickcount. I'll post the code in a second.

    Edit: Here you go...
    VB Code:
    1. Private CPUFreq As Currency
    2.  
    3. Public Sub InitTimer()
    4. Dim cFreq As Currency
    5.     Call QueryPerformanceFrequency(cFreq)
    6.     CPUFreq = CDbl(cFreq)
    7. End Sub
    8.  
    9. Public Function HiResTimer() As Double
    10. Dim PCounter As Currency
    11.     Call QueryPerformanceCounter(PCounter)
    12.     HiResTimer = CDbl(PCounter) / CPUFreq
    13. End Function
    "1 4m 4 1337 #4xz0r!'
    Janus

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80
    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?

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80
    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
  •  



Click Here to Expand Forum to Full Width