Results 1 to 12 of 12

Thread: Game Loop Speed on Different Machines

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Posts
    72

    Game Loop Speed on Different Machines

    In my game loop, I have it Sleep for 50ms on each loop so the speed is appropriate for my machine. However, when I install in on other machines, 50ms may be too fast or too slow.

    I realize I can give the user a speed up/slow down capability, but my game really needs to be a "standard" speed, so it looks the same on each machine -- otherwise the game dynamic is thrown off.

    So anyone have a recommended, tried and true way to do this before I start experimenting?

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    It depends on how many game ticks you want in a second, it seems that you want 20 (1000 / 50) so here's the code for that:
    VB Code:
    1. 'Declare Function GetTickCount()
    2. A = GetTickCount
    3. Do
    4.     B = GetTickCount
    5.     If B - A >= 50 Then
    6.         UpdateStuff
    7.         A = GetTickCount
    8.     End If
    9.     DrawStuff
    10. Loop
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Techi
    Guest

    simple game speed!

    to help confuse matters you can use the below code for simple games:

    Private Sub Form_Load()
    Dim count As Double ' set up count
    count2 = Timer ' count2 = timer function
    For count = 1 To 1000000 ' count from 1 to 1000000
    Next count ' then
    Inter = Timer - count2 ' take count2 from timer and store it as tmrInterval
    Inter = Inter * 400 ' times tmrInterval by 400
    Timer1.Interval = Inter
    MsgBox ("Game speed = " & Inter)
    MsgBox ("player 1 controls = d:up c:down x:left v:right")
    MsgBox ("player 2 controls = up:up down:down left:left right:right")
    End Sub

    The attatched file is a game i made for a pal to help him through his course!
    Attached Files Attached Files

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    My code is built for a DDraw loop..
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    Might wanna put that DrawStuff call into the If block. No need to redraw if nothing's been refreshed yet, and redrawing too often tends to slow yer comp a bit.. ;[
    To understand recursion, one must first understand the concept of recursion.

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Actually that may slow down the program more. :/
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    And might I add this is direct draw (probably full-screen exclusive!!) so you redraw as quickly as you can.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    Oh, I was thinking of BitBlt, which is what I'm using until I get off my lazy arse and learn DX X]
    To understand recursion, one must first understand the concept of recursion.

  9. #9
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221

    Fullscreen DDraw Framerate Balancing

    That's the verbose name for it. ^_^

    Simply redraw as fast as you can, and in your game loop, do something like this:

    Static LastTick as Long
    Dim CurrentTick as Long, NextTime as Long, Framerate as Long
    Framerate = 60 ' 60fps
    CurrentTick = GetTickCount
    If LastTick = 0 Then LastTick = CurrentTick
    NextTime = LastTick + (1000 / (Framerate))
    If CurrentTick >= NextTime Then
    LastTick = CurrentTick
    UpdateData ' Move all your sprites and stuff.
    End If
    Redraw ' Redraw.
    "1 4m 4 1337 #4xz0r!'
    Janus

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Hi Janus

    I see that you got my message on the RPGMaker forums (if you are that Janus )
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Posts
    72

    Thanks!

    Thanks everyone! I only now have seen your replies since for some reason I no longer seem to get email notifications.

  12. #12
    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
    Hey Sas, you said RPGMaker forums? The web page doesn't seem to work, so I can't get to them

    Can you give me a link or something?
    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."

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