That's the default framerate with a windowed screen. You can change it with the SetFrameRate() function.J. Baker wrote:Interesting, my max fps is 61 and this won't go higher. There must be a set room speed of 61. If anyone has got any different, please respond.
FPS?
Hey, thanks for the tip.chris_b wrote:That's the default framerate with a windowed screen. You can change it with the SetFrameRate() function.J. Baker wrote:Interesting, my max fps is 61 and this won't go higher. There must be a set room speed of 61. If anyone has got any different, please respond.
-
DriakTravo
- Enthusiast

- Posts: 346
- Joined: Fri Oct 10, 2003 12:42 am
- Location: Tampa,FL,USA
- Contact:
DriakTravo wrote:Can anyone tell me how to display the framerate using openscreen()?
Code: Select all
;- procedures
Procedure InitGameTimer()
Shared _GT_DevCaps.TIMECAPS
timeGetDevCaps_(_GT_DevCaps,SizeOf(TIMECAPS))
timeBeginPeriod_(_GT_DevCaps\wPeriodMin)
EndProcedure
Procedure StopGameTimer()
Shared _GT_DevCaps.TIMECAPS
timeEndPeriod_(_GT_DevCaps\wPeriodMin)
EndProcedure
;- _program start
;- _Init
If InitSprite()=0 Or InitKeyboard()=0
MessageRequester("ERROR","Cant init DirectX !",#MB_ICONERROR):End
EndIf
If OpenScreen(800,600,32,"Timing")=0
If OpenScreen(800,600,24,"Timing")=0
If OpenScreen(800,600,16,"Timing")=0
MessageRequester("ERROR","Cant open screen !",#MB_ICONERROR):End
EndIf:EndIf:EndIf
; timer initialisieren
InitGameTimer()
time = TimeGetTime_()
;- _game loop
Repeat
; calc framerate
If TimeGetTime_()-time >= 1000
time = TimeGetTime_()
FPS = Frames-1
Frames = 1
Else
Frames+1
EndIf
ClearScreen(0,0,0)
; show framerate
StartDrawing(ScreenOutput())
DrawingMode(1):FrontColor($80,$FF,$00)
Locate(50,50):DrawText(Str(FPS))
StopDrawing()
ExamineKeyboard()
FlipBuffers()
Until KeyboardPushed(#PB_KEY_ESCAPE)
;- _program end
StopGameTimer()You move sprites with the same speed on different PCs with
the following 'multiplicator' calculation:
Code: Select all
;- procedures
Procedure InitGameTimer()
Shared _GT_DevCaps.TIMECAPS
timeGetDevCaps_(_GT_DevCaps,SizeOf(TIMECAPS))
timeBeginPeriod_(_GT_DevCaps\wPeriodMin)
EndProcedure
Procedure StopGameTimer()
Shared _GT_DevCaps.TIMECAPS
timeEndPeriod_(_GT_DevCaps\wPeriodMin)
EndProcedure
;- variables
Global player1_move.f, player1_x.f, player1_y.f
;- _program start
;- _Init
If InitSprite()=0 Or InitKeyboard()=0
MessageRequester("ERROR","Cant init DirectX !",#MB_ICONERROR):End
EndIf
If OpenScreen(800,600,32,"Timing")=0
If OpenScreen(800,600,24,"Timing")=0
If OpenScreen(800,600,16,"Timing")=0
MessageRequester("ERROR","Cant open screen !",#MB_ICONERROR):End
EndIf:EndIf:EndIf
If CreateSprite(1,32,32)=0
CloseScreen()
MessageRequester("ERROR","Cant create sprite !",#MB_ICONERROR):End
Else
StartDrawing(SpriteOutput(1))
Box (0,0,32,32,$00FFFF)
Line(0,0,32,32,$000000)
Line(32,0,0,32,$000000)
StopDrawing()
EndIf
player1_speed.f = 0.350
; timer initialisieren
InitGameTimer()
StartTime = TimeGetTime_()
time = StartTime
;SetFrameRate(75)
;- _game loop
Repeat
; calculate multiplicator
multiplicator.f = StartTime
StartTime = TimeGetTime_()
multiplicator = StartTime - multiplicator
; calc framerate
If TimeGetTime_()-time >= 1000
time = TimeGetTime_()
FPS = Frames-1
Frames = 1
Else
Frames+1
EndIf
ClearScreen(0,0,0)
; show framerate
StartDrawing(ScreenOutput())
DrawingMode(1):FrontColor($80,$FF,$00)
Locate(50,50):DrawText("FrameRate: "+Str(FPS))
StopDrawing()
ExamineKeyboard()
; calc move-step for player1
player1_move = player1_speed * multiplicator
If KeyboardPushed(#PB_KEY_LEFT)
player1_x - player1_move : EndIf
If KeyboardPushed(#PB_KEY_RIGHT)
player1_x + player1_move : EndIf
If KeyboardPushed(#PB_KEY_UP)
player1_y - player1_move : EndIf
If KeyboardPushed(#PB_KEY_DOWN)
player1_y + player1_move : EndIf
If player1_x < -32 : player1_x = 800 : EndIf
If player1_x > 800 : player1_x = -32 : EndIf
If player1_y < -32 : player1_y = 600 : EndIf
If player1_y > 600 : player1_y = -32 : EndIf
DisplaySprite(1,player1_x,player1_y)
FlipBuffers()
Until KeyboardPushed(#PB_KEY_ESCAPE)
;- _program end
StopGameTimer()use: 60, 72, 85, 100 FPS...
-
DriakTravo
- Enthusiast

- Posts: 346
- Joined: Fri Oct 10, 2003 12:42 am
- Location: Tampa,FL,USA
- Contact:
It initializes the highres timer to the lowest possible valuecoma wrote:what does exactly do InitGameTimer() ?
If I remove it, "I got exactly the same result.
thats available, usually 1ms - but on some old systems
like Win95 and Win98 it *can* be higher, like 5ms.
On NT-Systems (NT4,2k,XP) it should always be 1ms.
It works on most systems without the initialization, but its
the correct way to do it - and i like correct programming if possible.
I've seen the difference on my dual-PIII-1000, some code
didnt work correctly. I wondered, read some MSDN, and
found the correct way.
With the correct initialization it works fine everywhere.
