October 25, 2021, 10:36:43 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
   Home   Help Search Login Register  
Pages: [1]
Author Topic: Game speed  (Read 4594 times)
Posts: 56

Coding since the 90's

« on: October 30, 2009, 10:41:39 PM »

Hey, I have an RPG engine which draws anywhere from 50 to 250 objects to the screen each cycle. It uses FBGFX (freebasic graphics lib.) My question is how can I control the game speed? What is the common way? Sleep 1 is not good. The speed fluctuates too much.

I have the following code now, and it somewhat works:

If Timer > t Then
t = Timer + .02
(get input)
(render graphics)
(put graphics to screen)
end if

Is that a recommended way of doing things? It seems to work okay except I realize I'm putting a lot of graphics to the screen and it slows it down. But even if there's a normal amount of graphics put to the screen, I don't want to speed to fluctuate, (character walking fast and then slowing down).

« Last Edit: October 30, 2009, 11:04:04 PM by toad » Logged

Posts: 84

« Reply #1 on: October 31, 2009, 05:17:23 PM »

Realistically TIMER accuracy is closer to .05 than .02, but that won't hurt anything. It ticks every 1/18th of a second. There are ways to change the ticks, but you still may get delays.

TIMER can be influenced by background Windows programs also, so there is no guarantee of a smooth speed unless you use pure DOS with no TSR (terminate-stay-resident) programs running.

QB64 has a _LIMIT function that allows you to run loops at so many loops per second (frames). You can also add sound using the soundboard instead of the PC speaker: www.QB64.net/forum
« Last Edit: October 31, 2009, 05:31:27 PM by Clippy » Logged

Pages: [1]
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!