Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with locking my game's speed at 40 FPS
#1
I want to lock the speed of my game at 40 FPS, but TIMER doesn't work Sad 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!!! Smile
Reply
#2
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]
Reply
#3
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]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)