VBGamer |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Sorry for the late reply... DiscoStew (2 replies, 0 views) (2000-Sep-18) ...but I have the solution to your problem.
This code was taking directly from the RPG-Creator that I am working on (if anyone remembers it) except for the comments shown:
'First declare the variables
Dim FPSLoop as Byte 'Our Frames per second value
Dim CPSLoop as Byte 'Our Cycles per second value
Dim DrawnFrame as Boolean 'Whether or not the current frame for this cycle has been drawn
Dim GetNextFrame as Boolean 'Whether or not to move onto the next frame
Dim StartingTick as Long 'The value of the DX.TickCount when the program starts
Dim CurrentTick as Long 'The actual tick count
Dim ShouldBeTick as Long 'What the tick count should be at
Dim ClockTick as Long 'Used for getting FPS and CPS each second
Const ConstTick = (1000 / 60) 'This is how many ticks are in each cycle
'This process also includes the use of the API function TickCount, but I use
'the DirectX TickCount instead which will be shown as dx.TickCount
'The next part involves the calculated data and the display of
'graphics. In order for this to work, you must separate the
'data being calculated and the graphics being drawn
Public Sub StartProg()
FPSLoop = 0
CPSLoop = 0
DrawnFrame = False
StartingTick = dx.TickCount
CurrentTick = 0
CurrentTick1 = 0
GetNextFrame = False
ClockTick = dx.TickCount
Do
If ((dx.TickCount - StartingTick) >= CurrentTick) Or (GetNextFrame = True) Then
'This is to make sure that the data runs at 60CPS
'Add your data calculation here
'The next 12 lines can be put into their own procedure if needed
CPSLoop = CPSLoop + 1
If dx.TickCount >= ClockTick + 1000 Then
CPS = CPSLoop
FPS = FPSLoop
CPSLoop = 0
FPSLoop = 0
ClockTick = dx.TickCount
End If
ShouldBeTick = CurrentTick + ConstTick
CurrentTick = (dx.TickCount - StartingTick)
DrawnFrame = False
GetNextFrame = False
End If
If CurrentTick > ShouldBeTick Then
'If there is no time to draw the next frame, it will go to the next cycle
GetNextFrame = True
DrawnFrame = True
End If
If DrawnFrame = False Then
'This makes sure that it will draw the next frame if it has enough time,
'and it prevents from drawing that same frame if it already has, creating
'some actual speed up
FPSLoop = FPSLoop + 1
'Add your graphic drawing here
DrawnFrame = True
End If
DoEvents
Loop
Exit Sub
End Sub
I hope that this will greatly benefit you. It took me quite some time to find out how to do this, and it helped me a lot.
|