Blitz3D+ Command Reference

Flip [vwait]

Parameters

vwait (optional) - 1 waits for the monitor's next refresh before showing the frame (default)
0 shows the frame immediately, letting the loop run as fast as it can

Description

Shows the back buffer on screen - the end-of-frame command in every game loop.

Games draw each frame out of sight on the back buffer, then call Flip to put the finished frame in front of the player in one go. That is what stops half-drawn frames and flicker: draw to BackBuffer(), and nothing is visible until Flip. A typical loop is Cls, draw everything, Flip - and in 3D, RenderWorld then Flip.

With vwait on (the default) the update is synchronised with the display's refresh, so movement looks smooth and the loop naturally runs at the monitor's rate - a free frame limiter. With Flip 0 frames appear as fast as your code can make them, which is mainly useful for benchmarking or for game loops that do their own timing (for example with a CreateTimer/WaitTimer pair or delta timing).

On the modern runtime the sync rides on the Windows desktop compositor, so tearing is not the issue it was on old hardware - vwait is about pacing. Flip also gives Windows a moment to process events, which keeps the window responsive. And unlike classic Blitz3D, which swapped the two buffers (leaving stale contents behind), the modern runtime copies the back buffer to the front - the back buffer keeps the frame you just drew, so drawing incrementally on it between Flips is safe.

Flip only applies to the display. Drawing on image or texture buffers needs no Flip - it is just not visible until you draw that image somewhere.

See also: BackBuffer, FrontBuffer, SetBuffer, VWait, Cls.

Example

; Flip Example
; ------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

vwait=1
frames=0
fps=0
timer=MilliSecs()
x#=0

While Not KeyDown(1)

    ; Space toggles Flip's vwait parameter
    If KeyHit(57) Then vwait=1-vwait

    ; A ball drifting across the screen
    x=x+3
    If x>640 Then x=-40

    Cls
    Color 0,200,255
    Oval x,220,40,40,1

    ; Count how many frames we manage per second
    frames=frames+1
    If MilliSecs()-timer>=1000 Then
        fps=frames
        frames=0
        timer=MilliSecs()
    EndIf

    Color 255,255,255
    Text 0,0,"Space: toggle vwait   Esc: exit"
    Text 0,20,"Flip "+vwait+"   ("+fps+" frames per second)"
    Text 0,40,"vwait=1 syncs to the monitor refresh; vwait=0 flips flat out"

    ; Flip shows the finished back buffer on screen
    Flip vwait

Wend

End

Index