I would like make a safety solution that control the speed of my games, in order to run the game same speed both on slow and fast computers.
I invented this code for this, what clocks the fps:
Code: Select all
dim as integer fps,frame
dim as double starttime
fps=0
frame=0
starttime=timer
do
cls
if timer-starttime>1 then
fps=frame
starttime=timer
frame=0
else
frame+=1
end if
print "ESC: exit, FPS: "& str(fps)
loop until inkey=Chr$(27)
I think if I can get the fps, then e.g. I can move the game objects by pixel amount, in inverse ratio to fps, so for example bigger fps would result in smaller move on a fast computer and less fps would result in larger move on a slow computer. Or I can give the suitable value to Sleep command.
I don't know, are these good conceptions?