|
-
Sep 3rd, 2002, 05:06 PM
#1
Thread Starter
Addicted Member
Game Loops
I'm new at actually making a full game, so I'm hoping someone can help me.
When you write a game loop, graphically speaking, you want it to run at or above around 30 fps, right? That means the game goes through all your items in the loop and draws all the images 30 times a second, right? Well, I've tried something like that where I have a ball and I animate it whenever the loop is called. The ball has an animation delay on it so it will only change frames so many times per second, say 10 or so. The problem is, if you let the loop run as fast as possible, without any time delay, it draws the the ball about 3000 times per second, and causes some serious lag with the mouse and such, even with DoEvents called in the loop. Should I put a time delay on the entire game loop?
-
Sep 3rd, 2002, 08:37 PM
#2
Junior Member
What you need to do, is add some sort of variable for the ball object called
(i make all "member" variables of "objects" or "classes" prefixed with m_)
and use the GetTickCount() api function to find out how much time has passed sense the last animation. ie.
VB Code:
if GetTickCount >= m_timeDelay + 10000 Then '10000 millaseconds is 10 seconds
Call doAnimation 'do what ever animation stuff here
m_timeDelay = GetTickCount()
End if
m_timeDelay + someINT is how long you want to wait before you do an action. (1000 = 1 second)
This wont effect game loop times so you can have a game loop 1/60 of a second (60 fps/60 loops per second) and only be animating or doing something a certain amount of time..
I hope that wasn't too ambigous.
EDIT: I use 10000 as the time delay becuase I misread your post and thought you wanted once per 10 seconds, instead of 10 times per second. use 10 for the latter.
-
Sep 3rd, 2002, 08:55 PM
#3
Frenzied Member
Screw delays =).
Here is what a professional game would use:
Code:
Dim tDelta As Single
Dim s As Long
Dim e As Long
...
While True 'Your game loop
s = GetTickCount()
'Do Stuff
DoEvents
e = GetTickCount()
tDelta = CSng(e - s) / 1000.0
Wend
tDelta holds the fraction of a second that has passed while the loop has run once. Simply hold a vector for the length you want your ball to move in one second, and multiply it by tDelta each time you add it to the currept position.
Z.
-
Sep 3rd, 2002, 10:34 PM
#4
Fanatic Member
That wouldn't fix the problem with the cpu lag from the loop. Only a delay can fix the cpu lag. That code would allow for super smooth animation, but it would still lag up other processes (like the mouse).
-
Sep 4th, 2002, 12:19 AM
#5
Junior Member
Originally posted by Zaei
Screw delays =).
Here is what a professional game would use:
Code:
Dim tDelta As Single
Dim s As Long
Dim e As Long
...
While True 'Your game loop
s = GetTickCount()
'Do Stuff
DoEvents
e = GetTickCount()
tDelta = CSng(e - s) / 1000.0
Wend
tDelta holds the fraction of a second that has passed while the loop has run once. Simply hold a vector for the length you want your ball to move in one second, and multiply it by tDelta each time you add it to the currept position.
Z.
While your "PROFESSIONAL" code would be standard for movement, it doesn't work for what (his wording at least) implied. Which as I read it was, "how can I animate a ball 10 times every second?"
So THERE!! My answer is better then yours (sure context is a technicality, but if its good enough in court...)
But I will admit that as far as movement calculations, your method would be the way to go.
I had read his question to be concerning more "Sprite Animation" then "Movement Animation" (again based on context). In which my answer would be the victor.
-
Sep 4th, 2002, 06:05 AM
#6
Frenzied Member
Actually, the first sentence of his post implies that he wants to make a full game, so why post code that would not be as useful to that end?
Z.
-
Sep 4th, 2002, 02:16 PM
#7
Junior Member
It useful.
Especially for sprite animation, where graphics are based on a bitmap of several renderings of an animation. While you may think running through those animations at hyperspeed isnt it a problem, it is. Sprite animations are ment to happen at specific intervals.
My Code specificly has purpose for sprite animation (which As I stated was what I thought he wanted).
Infact I would say my code is twice as useful as yours. Becuase not only can it do its purpose, but it CAN (maybe not super smooth) do movement animation as well.
!
-
Sep 4th, 2002, 02:53 PM
#8
Frenzied Member
This is not worth arguing over. You do it your way, Ill do it mine. jmiller can choose which method he prefers.
Z.
-
Sep 4th, 2002, 11:06 PM
#9
Addicted Member
Originally posted by Zaei
Here is what a professional game would use:
Hate to tell you, but a professional game wouldn't use that as professional games are written in C/C++.
-
Sep 5th, 2002, 06:04 AM
#10
Frenzied Member
Concepts are language independent =).
Z.
-
Sep 5th, 2002, 06:45 AM
#11
Good Ol' Platypus
Fight Fight Fight
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Sep 5th, 2002, 10:16 AM
#12
Frenzied Member
Originally posted by Sastraxi
Fight Fight Fight
Yeah, im really getting hammered on this one =).
Z.
-
Sep 5th, 2002, 10:54 AM
#13
And to make you feel even more bad, a professional game would probably query the performance counter, if available. Just look at the D3D framework that comes with the C++ DX8 SDK.

Don't take me to seriously...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 5th, 2002, 11:06 AM
#14
Frenzied Member
Hey, im already doing ALL of this (including the QPC() and QPF() calls, and in C++), so I dont feel bad at all =).
And besides, When you are using VB, there isnt THAT much point in using QueryPERFORMANCECounter() =).
Z.
-
Sep 5th, 2002, 11:20 AM
#15
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 5th, 2002, 02:59 PM
#16
Good Ol' Platypus
But there is a little
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
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
|