PCopy
Copies one graphical or text page onto another
Syntax
`
Declare Sub PCopy ( ByVal source As Integer = -1, ByVal destination As Integer = -1 )
`
Usage
`
PCopy [ source ] [, destination ]
`
Parameters
`source`
page to copy from
`destination`
page to copy to
Description
Copies one graphical or text video page to another. Useful for drawing all graphics on one invisible page and copying it to the active visible page - creating smooth graphics and animation. Known as 'double buffering' or 'page flipping'.
`source` and `destination` refer to page numbers. The 'source' page is copied over the 'destination' page when pcopy is called.
If the `source` argument is omitted, the current working page is assumed. If the `destination` page is omitted, the current visible page is assumed.
Example
`
ScreenRes 320, 240, 32, 2 'Sets up the screen to be 320x240 in 32-bit color with 2 video pages.
Dim As Integer max_x_value = 270, x_value = 50 'Dimension our working variables.
Do While x_value < max_x_value 'Loop while x_value is less than the max
ScreenSet 2,1 'Sets the working page to 2 and the displayed page to 1
Cls 'Clears the screen so we can start fresh
Circle (x_value,50),50,&h00FFFF00 'Draws a circle with a 50 pixel radius in yellow on page 2
ScreenSet 1,1 'Sets the working page to 1 and the displayed page to 1
ScreenSync 'Waits for vertical refresh
PCopy 2,1 'Copies our circle from page 2 to page 1
x_value += 1 'Increments x_value so it will move.
Sleep 25 'Waits for 25 milliseconds.
Loop 'Goes back to do as long as x_value is less than x_max_value
Sleep 'Waits for any key to be pressed so you can see the work done.
`
Example
`
' Console mode example:
'' set the working page number to 0, and the visible page number to 1
#if __FB_LANG__ = "QB"
Screen ,, 0, 1
#else
Screen , 0, 1
#endif
Dim As Integer i, frames, fps
Dim As Double t
t = Timer
Do
'' fill working page with a certain color and character
Cls
Locate 1, 1
Color (i And 15), 0
Print String$(80 * 25, Hex$(i, 1));
i += 1
'' show frames per second
Color 15, 0
Locate 1, 1
Print "fps: " & fps,
If Int(t) <> Int(Timer) Then
t = Timer
fps = frames
frames = 0
End If
frames += 1
'' copy working page to visible page
PCopy
'' sleep 50ms per frame to free up cpu time
Sleep 50, 1
'' run loop until user presses a key
Loop Until Len(Inkey$)
`
Platform Differences

- Maximum number of text pages in Windows is 4.
- Maximum number of text pages in DOS is 8.
- Maximum number of text pages in all other targets is 1.
- Maximum number of graphics pages depends on what was specified when the `Screen` or `ScreenRes` statement was called.

Differences from QB

- None

See also

- `ScreenCopy`
- `Flip`
- `Screen`