Posts: 42
Threads: 6
Joined: Dec 2004
I want to lock the speed of my game at 40 FPS, but TIMER doesn't work
Also, FOR..NEXT loop will be faster on faster CPU-s and slower on old and slow CPU-s... Is there any other way to keep the game running at 40 FPS? Please help! :bounce:
EEL THE BEAT OF EURODANCE!!!
Posts: 320
Threads: 9
Joined: Dec 2004
For an update frequency of 40Hz, you must ensure that each update cycle is 1/40 = 0.025 seconds. You can use timer to do this if you record the time at the top of your main loop and the time at the end.
Example:
[syntax="QBASIC"]
DO
startTime! = TIMER
' update the game rules here.
' update the display here.
WHILE TIMER < startTime! + 0.025: WEND
LOOP UNTIL exitCondition
[/syntax]
Haven't tested this, but it should theoretically work. I'm used to having millisecond-timers available, but I guess because this is only 40Hz, QB's timer will suffice.
If you have moving objects in your game, you can record the elapsed time after the WHILE statement. For example:
[syntax="QBASIC"]
elapsed! = startTime! - TIMER
[/syntax]
This value can then be used to update the objects in the physical world, ensuring that your game will run at the correct speed no matter what the speed of the computer running it is.
-shiftLynx
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Posts: 1,845
Threads: 44
Joined: Aug 2002
Still, I recommend locking it at 60fps or 30fps. It's easy then to use the automatic vsync timer.
[syntax="QB"]WAIT &H3DA, 8
WAIT &H3DA, 8, 8[/syntax]