Sync
Sync
 
Parameters: NONE
Returns: NONE
 

      The Sync command displays the graphics that have been drawn to us, without it, we won't see anything !

      Sync is required as the screen we created from the OpenScreen command, doesn't just use one image to represent the game screen, there's actually two! These screens shall be known as the Front and Back screens.

      The Front is the visible version of the screen image, while the Back is a version that your actually drawing to. Once drawing is complete, we then swap (via Sync) the Back and Front images over and start the drawing process again. So the image that we've just completed drawing to, the back screen, becomes visible to us (I.e it becomes the Front screen) while the previous visible image is now hidden to us (it becomes the Back Screen)

      Those familiar with computer graphics, will no doubt know this as Double Buffering. It's this approach that lets our programs appear to draw smoothly to the monitor, as without it, they would flicker and flash horribly! This is not to be confusing with a graphical glitch called 'tearing' which often occurs when your computers graphics hardware tried to display the Front screen while the Sync is in progress. Which can generally be eliminated via activating ScreenVsync. But will give you slower overall performance.



FACTS:


      * Sync and SwapScreen have identical functionality. Both swap the hidden screens information (back) to the visible screen (front) for you.

      * Note: Double Buffering behaves differently in Window and Full Screen modes. In a windowed screen mode, the front screen is considered the actual Window. In this case, Rather than swapping Front->Back and Back->Front, the Back Screen image is copied over the Front Screen image. While in full screen modes your graphic card we generally swap the buffers via indirection (a pointer swap), which is the fastest solution, but not all Video cards support this approach. So ome cards work the same in Full Screen mode and windowed.

      * PlayBASIC uses the Sync process to help the user control the games frame rate, by preventing the game from running too fast if you require. You can set your preferred frame rate using the SetFps command.






Mini Tutorial #1:


      This examples draws 100 random circle graphics, then uses Sync to show us the results...

  
  
; Draw 100 circles to the BACK screen...
  For lp 1 To 100
     Circle Rnd(100),Rnd(100),50,1
  Next
  
; Display the Screen.. This will copy the BACK Screen to
; the FRONT, so it's visible to the user.
  Sync
  
; Wait for a key press
  WaitKey
  






Mini Tutorial #2 - Basic Computer Animation:


      This example shows a circle moving across the screen from LEFT to RIGHT. Each time through the Main (DO/LOOP) the program clears the screen to black, Adds one to our XPOS varibale, Renders a Circle using the Xpos variable as it's X coordinate and renders a text message using print. Once we've finished drawing we then call Sync to



  
  
; Tell PlayBASIC to limit the program speed to 60(or less)
; frame updates (syncs) per second
  SetFPS 60
  
  
; start a Do/Loop
  Do
     
   ; Clear the screen (backbuffer)
     Cls RGB(0,0,0)
     
   ; add one to the Xpos and wrap it with in 0 to 799
     Xpos=Mod(Xpos+1,800)
     
     
   ; draw a circle at this position on the
   ; screens back buffer
     Circle Xpos,300,50
     
     
   ; draw the message to the screen
     Print "Press ESC to END"
     
     
   ; Display the screen, swaps the newly drawn
   ; back buffer to the front
     Sync
     
     
   ; jump back to the DO statement to keep this program running
  Loop EscKey()=true
  
  





 
Related Info: FPS | GetScreenType | GetScreenVSync | OpenScreen | ScreenVsync | SetFPS | SwapScreen :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com