Below is an example...
On line 1, you can switch between windowed mode or full screen by setting windowed.l to 0 (full screen) or 1 (windowed).
In full screen mode, the animation is completely smooth. But in windowed mode, there's a small "jump" in the animation every second or so.
Why?
Isn't FlipBuffers supposed to wait for vertical refresh? It seems it sometimes doesn't, or perhaps it waits too long... (I can't tell if it's skipping a frame or painting a frame too late)
My monitor is running at 60 FPS, and my system has loads of CPU power and plenty of RAM to go around... I've tried on three different systems, and this frame skipping/doubling occurs on all of them...
Any ideas?
thanks! :)
(code below...)
Code: Select all
windowed.l = 1
width.l = 512
height.l = 288
boxw.l = 30
boxh.l = 30
maxx.l = width - boxw
maxy.l = height - boxh
If InitSprite() = 0
MessageRequester("Error", "Can't open screen & sprite enviroment!", 0)
End
EndIf
If Windowed
If OpenWindow(0, 0, 0, width, height, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If Not OpenWindowedScreen(WindowID(0), 0, 0, width, height, 0, 0, 0)
MessageRequester("Error", "Can't open windowed screen!", 0)
End
EndIf
EndIf
Else
SetRefreshRate(60)
If Not OpenScreen(640,480,32,"Screen")
MessageRequester("Error", "Can't open screen!", 0)
End
EndIf
EndIf
If Not InitKeyboard()
MessageRequester("Error", "Can't init keyboard!", 0)
End
EndIf
CreateSprite(0, 30, 30)
If StartDrawing(SpriteOutput(0))
Box(0, 0, 30, 30, RGB(255, 0, 0))
Box(5, 5, 20, 20, RGB(0, 255, 0))
Box(10, 10, 10, 10, RGB(0, 0, 255))
StopDrawing()
EndIf
If Not windowed : SetFrameRate(60) : EndIf
dx.f = 2
dy.f = 1
Repeat
FlipBuffers(1)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape) : End : EndIf
If windowed
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
EndIf
ClearScreen(RGB(0, 0, 0))
x = x + dx
y = y + dy
If x > maxx : x = maxx : dx = -dx : EndIf
If x < 0 : x = 0 : dx = -dx : EndIf
If y > maxy : y = maxy : dy = -dy : EndIf
If y < 0 : y = 0 : dy = -dy : EndIf
DisplaySprite(0, x, y)
ForEver

