PCOPY: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "The PCOPY statement copies one source screen page to a destination page in memory. {{PageSyntax}} : PCOPY {{Parameter|sourcePage%}}, {{Parameter|destinationPage%}} {{PageDescription}} * {{Parameter|sourcePage%}} is an image page in video memory. * {{Parameter|destinationPage%}} is the video memory location to copy the source image to. * The working page is set as 0. All drawing occurs there. * The visible page is set as any page number that the SCREEN mode a...") |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The [[PCOPY]] statement copies one source screen page to a destination page in memory. | The [[PCOPY]] statement copies one source screen page to a destination page in memory. | ||
Line 14: | Line 14: | ||
* The '''QB64''' [[_DISPLAY]] statement can also be used to stop screen flicker without page flipping or [[CLS]] and '''is the recommended practice'''. | * The '''QB64''' [[_DISPLAY]] statement can also be used to stop screen flicker without page flipping or [[CLS]] and '''is the recommended practice'''. | ||
=== QBasic/QuickBASIC === | |||
==QBasic/QuickBASIC== | |||
* {{Parameter|sourcePage%}} and {{Parameter|destinationPage%}} numbers are limited by the SCREEN mode used. In '''QB64''', the same limits don't apply. | * {{Parameter|sourcePage%}} and {{Parameter|destinationPage%}} numbers are limited by the SCREEN mode used. In '''QB64''', the same limits don't apply. | ||
Line 22: | Line 21: | ||
''Example 1:'' Creating a mouse cursor using a page number that '''you create''' in memory without setting up page flipping. | ''Example 1:'' Creating a mouse cursor using a page number that '''you create''' in memory without setting up page flipping. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl | {{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(640, 480, 32) 'any graphics mode should work without setting up pages | ||
{{Cl|_MOUSEHIDE}} | {{Cl|_MOUSEHIDE}} | ||
SetupCursor | SetupCursor | ||
{{Cl|PRINT}} "Hello World!" | {{Cl|PRINT}} "Hello World!" | ||
{{Cl|DO}}: {{Cl|_LIMIT}} 30 | {{Cl|DO}}: {{Cl|_LIMIT}} 30 | ||
{{Cl|DO}} {{Cl|WHILE}} {{Cl|_MOUSEINPUT}}: {{Cl|LOOP}} 'main loop must contain _MOUSEINPUT | {{Cl|DO}} {{Cl|WHILE}} {{Cl|_MOUSEINPUT}}: {{Cl|LOOP}} 'main loop must contain _MOUSEINPUT | ||
' other program code | ' other program code | ||
{{Cl|LOOP}} | {{Cl|LOOP}} | ||
{{Cl|SUB}} SetupCursor | {{Cl|SUB}} SetupCursor | ||
{{Cl|ON TIMER(n)|ON TIMER}}(0.02) UpdateCursor | {{Cl|ON TIMER(n)|ON TIMER}}(0.02) UpdateCursor | ||
{{Cl|TIMER}} ON | {{Cl|TIMER}} {{Cl|ON}} | ||
{{Cl|END SUB}} | {{Cl|END SUB}} | ||
Line 42: | Line 41: | ||
{{Cl|_DISPLAY}} 'statement shows image | {{Cl|_DISPLAY}} 'statement shows image | ||
{{Cl|PCOPY}} 100, {{Cl|_DISPLAY (function)|_DISPLAY}} 'function return as destination page | {{Cl|PCOPY}} 100, {{Cl|_DISPLAY (function)|_DISPLAY}} 'function return as destination page | ||
{{Cl|END SUB}} | {{Cl|END SUB}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
:''Note:'' Works with [[_DISPLAY (function)]] as the other page. If mouse reads are not crucial, put the _MOUSEINPUT loop inside of the UpdateCursor Sub. | :''Note:'' Works with [[_DISPLAY (function)]] as the other page. If mouse reads are not crucial, put the _MOUSEINPUT loop inside of the UpdateCursor Sub. | ||
Line 48: | Line 47: | ||
''Example 2:'' Bouncing balls | ''Example 2:'' Bouncing balls | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl | {{Cl|SCREEN}} 7, 0, 1, 0 | ||
{{Cl|DIM}} x(10), y(10), dx(10), dy(10) | {{Cl|DIM}} x(10), y(10), dx(10), dy(10) | ||
{{Cl|FOR...NEXT|FOR}} a = 1 {{Cl|TO}} 10 | {{Cl|FOR...NEXT|FOR}} a = 1 {{Cl|TO}} 10 | ||
Line 61: | Line 60: | ||
{{Cl|CLS}} | {{Cl|CLS}} | ||
{{Cl|_LIMIT}} 100 'regulates speed of balls in QB64 | {{Cl|_LIMIT}} 100 'regulates speed of balls in QB64 | ||
{{Cl|FOR...NEXT|FOR}} a = 1 {{Cl|TO}} 10 | {{Cl|FOR...NEXT|FOR}} a = 1 {{Cl|TO}} 10 | ||
{{Cl|CIRCLE}}(x(a), y(a)), 5, 15 'all erasing and drawing is done on page 1 | {{Cl|CIRCLE}}(x(a), y(a)), 5, 15 'all erasing and drawing is done on page 1 | ||
x(a) = x(a) + dx(a) | x(a) = x(a) + dx(a) | ||
Line 77: | Line 76: | ||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
* [[_DISPLAY]] | * [[_DISPLAY]] | ||
* [[SCREEN | * [[SCREEN]] | ||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 17:00, 24 February 2023
The PCOPY statement copies one source screen page to a destination page in memory.
Syntax
- PCOPY sourcePage%, destinationPage%
Description
- sourcePage% is an image page in video memory.
- destinationPage% is the video memory location to copy the source image to.
- The working page is set as 0. All drawing occurs there.
- The visible page is set as any page number that the SCREEN mode allows.
- The _DISPLAY (function) return can be used a page number reference in QB64 (See Example 1).
- The QB64 _DISPLAY statement can also be used to stop screen flicker without page flipping or CLS and is the recommended practice.
QBasic/QuickBASIC
- sourcePage% and destinationPage% numbers are limited by the SCREEN mode used. In QB64, the same limits don't apply.
Examples
Example 1: Creating a mouse cursor using a page number that you create in memory without setting up page flipping.
SCREEN _NEWIMAGE(640, 480, 32) 'any graphics mode should work without setting up pages _MOUSEHIDE SetupCursor PRINT "Hello World!" DO: _LIMIT 30 DO WHILE _MOUSEINPUT: LOOP 'main loop must contain _MOUSEINPUT ' other program code LOOP SUB SetupCursor ON TIMER(0.02) UpdateCursor TIMER ON END SUB SUB UpdateCursor PCOPY _DISPLAY, 100 'any page number as desination with the _DISPLAY function as source PSET (_MOUSEX, _MOUSEY), _RGB(0, 255, 0) DRAW "ND10F10L3F5L4H5L3" _DISPLAY 'statement shows image PCOPY 100, _DISPLAY 'function return as destination page END SUB |
- Note: Works with _DISPLAY (function) as the other page. If mouse reads are not crucial, put the _MOUSEINPUT loop inside of the UpdateCursor Sub.
Example 2: Bouncing balls
SCREEN 7, 0, 1, 0 DIM x(10), y(10), dx(10), dy(10) FOR a = 1 TO 10 x(a) = INT(RND * 320) + 1 y(a) = INT(RND * 200) + 1 dx(a) = (RND * 2) - 1 dy(a) = (RND * 2) - 1 NEXT DO PCOPY 1, 0 'place image on the visible page 0 CLS _LIMIT 100 'regulates speed of balls in QB64 FOR a = 1 TO 10 CIRCLE(x(a), y(a)), 5, 15 'all erasing and drawing is done on page 1 x(a) = x(a) + dx(a) y(a) = y(a) + dy(a) IF x(a) > 320 THEN dx(a) = -dx(a): x(a) = x(a) - 1 IF x(a) < 0 THEN dx(a) = -dx(a): x(a) = x(a) + 1 IF y(a) > 200 THEN dy(a) = -dy(a): y(a) = y(a) - 1 IF y(a) < 0 THEN dy(a) = -dy(a): y(a) = y(a) + 1 NEXT LOOP UNTIL INKEY$ = CHR$(27) ' escape exit |
- Explanation: PCOPY reduces the flickering produced by clearing the screen. x(a) = x(a) - 1, etc. is just to be safe that the balls stay within the boundaries. dx(a) = -dx(a), etc. is to keep the actual speed while inverting it (so that the ball "bounces"). The rest should be self-explanatory, but if you are unsure about arrays you might want to look at QB64 Tutorials -> Arrays.
See also