Yes, that's the way a flicker free 2d program works.
You draw something in a buffer and show it.
then you draw the next screen into a hidden buffer and then you use FipBuffers() to switch them in a pause, that you will not recognize
any flicker.
In earlier days you wait on the vertical backtrace to do this.
But this has nothing todo with PB, that's the way buffered drawing is working.
So I think your method is wrong.
You can create 2 Sprites and change the sprite which should be displayed.
Maybe this gives you an idea:
Code: Select all
#xres = 800: #yres = 600
LoadFont(0, "Verdana", 14)
InitSprite()
OpenWindow(0, 0, 0, #xres, #yres, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #xres, #yres)
CreateSprite(0, #xres, #yres)
CreateSprite(1, #xres, #yres)
If StartDrawing(SpriteOutput(0))
DrawingFont(FontID(0))
t = ElapsedMilliseconds()
For i=1 To 2000000
;event = WindowEvent() ; ====== LINE A ======
x = Random(#xres-1)
y = Random(#yres-1)
color = Random($ffffff)
Plot(x, y, color)
Next
DrawText(5, 5, Str(ElapsedMilliseconds() - t), RGB(255, 255, 255))
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(1))
DrawingFont(FontID(0))
t = ElapsedMilliseconds()
For i=1 To 2000000
;event = WindowEvent() ; ====== LINE A ======
x = Random(#xres-1)
y = Random(#yres-1)
color = Random($ffffff)
Plot(x, y, color)
Next
DrawText(5, 5, Str(ElapsedMilliseconds() - t), RGB(255, 255, 255))
StopDrawing()
EndIf
SpriteNo = 0
DisplaySprite(SpriteNo, 0, 0)
AddWindowTimer(0, 0, 3000)
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_Timer
If EventTimer() = 0
Debug "Change Sprite"
SpriteNo + 1
If SpriteNo = 2
SpriteNo = 0
EndIf
EndIf
Case #PB_Event_CloseWindow
Exit = #True
EndSelect
Until Event = 0
FlipBuffers()
ClearScreen(0)
DisplaySprite(SpriteNo, 0, 0)
Until Exit
Maybe screen is the wrong way for you.
If you have no 'realtime' changes, why not use simply a CanvasGadget and draw different images on it?