DISPLAY: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
m (Protected "DISPLAY" ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite)))
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:_DISPLAY}}
{{DISPLAYTITLE:_DISPLAY}}
The [[_DISPLAY]] statement turns off the automatic display while only displaying the screen changes when called.  
The [[_DISPLAY]] statement turns off the automatic display while only displaying the screen changes when called.




{{PageSyntax}}  
{{PageSyntax}}
: [[_DISPLAY]]
: [[_DISPLAY]]


Line 18: Line 18:
{{PageExamples}}
{{PageExamples}}
''Example 1:'' Displaying a circle bouncing around the screen.
''Example 1:'' Displaying a circle bouncing around the screen.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|SCREEN (statement)|SCREEN}} 12
{{Cl|SCREEN}} {{Text|12|#F580B1}}
x = 21: y =31             'start position
x = {{Text|21|#F580B1}}: y = {{Text|31|#F580B1}} {{Text|<nowiki>'start position</nowiki>|#919191}}
dx = 3: dy = 3             'number of pixel moves per loop      
dx = {{Text|3|#F580B1}}: dy = {{Text|3|#F580B1}} {{Text|<nowiki>'number of pixel moves per loop</nowiki>|#919191}}
{{Cl|DO}}
{{Cl|DO}}
     {{Cl|_LIMIT}} 100       ' set to 100 frames per second
     {{Cl|_LIMIT}} {{Text|100|#F580B1}} {{Text|<nowiki>' set to 100 frames per second</nowiki>|#919191}}
     x = x + dx: y = y + dy
     x = x + dx: y = y + dy
     {{Cl|IF...THEN|IF}} x < 0 {{Cl|OR}} x > 640 {{Cl|THEN}} dx = -dx 'limit columns and reverse column direction each side
     {{Cl|IF}} x < {{Text|0|#F580B1}} {{Cl|OR (boolean)|OR}} x > {{Text|640|#F580B1}} {{Cl|THEN}} dx = -dx {{Text|<nowiki>'limit columns and reverse column direction each side</nowiki>|#919191}}
     {{Cl|IF...THEN|IF}} y < 0 {{Cl|OR}} y > 480 {{Cl|THEN}} dy = -dy 'limit rows and reverse row direction top or bottom
     {{Cl|IF}} y < {{Text|0|#F580B1}} {{Cl|OR (boolean)|OR}} y > {{Text|480|#F580B1}} {{Cl|THEN}} dy = -dy {{Text|<nowiki>'limit rows and reverse row direction top or bottom</nowiki>|#919191}}
     IF px <> x OR py <> y THEN FOR d = 1 to 20: CIRCLE (px, py), d, 0: NEXT 'erase
     {{Cl|IF}} px <> x {{Cl|OR (boolean)|OR}} py <> y {{Cl|THEN}} {{Cl|FOR}} d = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|20|#F580B1}}: {{Cl|CIRCLE}} (px, py), d, {{Text|0|#F580B1}}: {{Cl|NEXT}} {{Text|<nowiki>'erase</nowiki>|#919191}}
     FOR c = 1 TO 20: {{Cl|CIRCLE}} (x, y), c, 6: NEXT 'draw new circle at new position
     {{Cl|FOR}} c = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|20|#F580B1}}: {{Cl|CIRCLE}} (x, y), c, {{Text|6|#F580B1}}: {{Cl|NEXT}} {{Text|<nowiki>'draw new circle at new position</nowiki>|#919191}}
     px = x: py = y       'save older coordinates to erase older circle next loop
     px = x: py = y {{Text|<nowiki>'save older coordinates to erase older circle next loop</nowiki>|#919191}}
     {{Cl|_DISPLAY}}               'after new circle is set, show it
     {{Cl|_DISPLAY}} {{Text|<nowiki>'after new circle is set, show it</nowiki>|#919191}}
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = CHR$(27) '' ''
{{Cl|DO...LOOP|LOOP UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}({{Text|27|#F580B1}})
{{CodeEnd}}
{{CodeEnd}}
:''Explanation:'' The loop is set with [[_LIMIT]] to 100 frames per second to limit CPU usage and the speed of the ball. Each loop a circle is drawn while the previous one is erased when the coordinates change. _DISPLAY only shows the new circle position once each loop. The '''_DISPLAY''' routine eliminates the need for setting [[SCREEN]] swap pages, [[CLS]] and [[PCOPY]]. _DISPLAY keeps the image off of the screen until the changes have all completed. Drawing 40 circles every loop helps slow down the ball.


:''Explanation:'' The loop is set with [[_LIMIT]] to 100 frames per second to limit CPU usage and the speed of the ball. Each loop a circle is drawn while the previous one is erased when the coordinates change. _DISPLAY only shows the new circle position once each loop. The '''_DISPLAY''' routine eliminates the need for setting [[SCREEN (statement)|SCREEN]] swap pages, [[CLS]] and [[PCOPY]]. _DISPLAY keeps the image off of the screen until the changes have all completed. Drawing 40 circles every loop helps slow down the ball.
----
 


''Example 2:'' [[_DISPLAY]] must be used to render hardware images placed with [[_PUTIMAGE]] ('''version 1.000 and up''').
''Example 2:'' [[_DISPLAY]] must be used to render hardware images placed with [[_PUTIMAGE]] ('''version 1.000 and up''').
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|CONST}} MenuHeight = 200
{{Cl|CONST}} MenuHeight = {{Text|200|#F580B1}}




{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(640, 480, 32)
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}({{Text|640|#F580B1}}, {{Text|480|#F580B1}}, {{Text|32|#F580B1}})
'{{Cl|SLEEP}} 1
{{Text|<nowiki>'SLEEP 1</nowiki>|#919191}}
{{Cl|LOCATE}} 20
{{Cl|LOCATE}} {{Text|20|#F580B1}}
DO
{{Cl|DO}}
     {{Cl|_LIMIT}} 30
     {{Cl|_LIMIT}} {{Text|30|#F580B1}}
     DisplayMenu
     {{Text|DisplayMenu|#55FF55}}
     k = {{Cl|_KEYHIT}}
     k = {{Cl|_KEYHIT}}
     {{Cl|IF...THEN|IF}} k <> 0 {{Cl|THEN}} {{Cl|PRINT}} k,
     {{Cl|IF}} k <> {{Text|0|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} k,
{{Cl|LOOP}} {{Cl|UNTIL}} k = 32 {{Cl|OR (boolean)|OR}} k = 27
{{Cl|DO...LOOP|LOOP UNTIL}} k = {{Text|32|#F580B1}} {{Cl|OR (boolean)|OR}} k = {{Text|27|#F580B1}}




{{Cl|SUB}} DisplayMenu
{{Cl|SUB}} {{Text|DisplayMenu|#55FF55}}
{{Cl|STATIC}} init, MS_HW {{Cl|AS}} {{Cl|LONG}}
    {{Cl|STATIC}} init, MS_HW {{Cl|AS}} {{Cl|LONG}}
{{Cl|IF...THEN|IF}} {{Cl|NOT}} init {{Cl|THEN}}
    {{Cl|IF}} {{Cl|NOT}} init {{Cl|THEN}}
    init = -1
        init = {{Text|-1|#F580B1}}
    MS = {{Cl|_NEWIMAGE}}(640, MenuHeight, 32) 'MenuScreen image
        MS = {{Cl|_NEWIMAGE}}({{Text|640|#F580B1}}, MenuHeight, {{Text|32|#F580B1}}) {{Text|<nowiki>'MenuScreen image</nowiki>|#919191}}
    D = {{Cl|_DEST}}: {{Cl|_DEST}} MS
        D = {{Cl|_DEST (function)|_DEST}}: {{Cl|_DEST}} MS
    {{Cl|CLS}} , {{Cl|&H}}FFAAAAAA 'background color gray
        {{Cl|CLS}} , {{Text|&HFFAAAAAA|#F580B1}} {{Text|<nowiki>'background color gray</nowiki>|#919191}}
    {{Cl|_PRINTSTRING}} (20, 2), "Menu Test" 'image text
        {{Cl|_PRINTSTRING}} ({{Text|20|#F580B1}}, {{Text|2|#F580B1}}), {{Text|<nowiki>"Menu Test"</nowiki>|#FFB100}} {{Text|<nowiki>'image text</nowiki>|#919191}}
    MS_HW = {{Cl|_COPYIMAGE}}(MS, 33) 'create the MenuScreen_HardWare image
        MS_HW = {{Cl|_COPYIMAGE}}(MS, {{Text|33|#F580B1}}) {{Text|<nowiki>'create the MenuScreen_HardWare image</nowiki>|#919191}}
    {{Cl|_FREEIMAGE}} MS
        {{Cl|_FREEIMAGE}} MS
    {{Cl|_DEST}} D
        {{Cl|_DEST}} D
{{Cl|END IF}}
    {{Cl|END IF}}
{{Cl|_PUTIMAGE}} (0, 0)-(640, MenuHeight), MS_HW
    {{Cl|_PUTIMAGE}} ({{Text|0|#F580B1}}, {{Text|0|#F580B1}})-({{Text|640|#F580B1}}, MenuHeight), MS_HW
{{Cl|_DISPLAY}}
    {{Cl|_DISPLAY}}
{{Cl|END SUB}} '' ''
{{Cl|END SUB}}
{{CodeEnd}}{{small|Code adapted by Galleon}}
{{CodeEnd}}
{{Small|Code adapted by Galleon}}
: ''Notes:'' When _DISPLAY is commented out, the hardware Menu Test screen portion will blink and key codes may be seen underneath.
: ''Notes:'' When _DISPLAY is commented out, the hardware Menu Test screen portion will blink and key codes may be seen underneath.



Latest revision as of 10:33, 24 March 2023

The _DISPLAY statement turns off the automatic display while only displaying the screen changes when called.


Syntax

_DISPLAY


Description

  • _DISPLAY turns off the auto refresh screen default _AUTODISPLAY behavior. Prevents screen flickering.
  • Call _DISPLAY each time the screen graphics are to be displayed. Place call after the image has been changed.
  • Re-enable automatic display refreshing by calling _AUTODISPLAY. If it isn't re-enabled, things may not be displayed later.
  • _DISPLAY tells QB64 to render all of the hardware _PUTIMAGE commands loaded into the buffer previously.
  • The _AUTODISPLAY (function) can be used to detect the current display behavior.
  • QB64 can set the graphic rendering order of _SOFTWARE, _HARDWARE, and _GLRENDER with _DISPLAYORDER.


Examples

Example 1: Displaying a circle bouncing around the screen.

SCREEN 12
x = 21: y = 31 'start position
dx = 3: dy = 3 'number of pixel moves per loop
DO
    _LIMIT 100 ' set to 100 frames per second
    x = x + dx: y = y + dy
    IF x < 0 OR x > 640 THEN dx = -dx 'limit columns and reverse column direction each side
    IF y < 0 OR y > 480 THEN dy = -dy 'limit rows and reverse row direction top or bottom
    IF px <> x OR py <> y THEN FOR d = 1 TO 20: CIRCLE (px, py), d, 0: NEXT 'erase
    FOR c = 1 TO 20: CIRCLE (x, y), c, 6: NEXT 'draw new circle at new position
    px = x: py = y 'save older coordinates to erase older circle next loop
    _DISPLAY 'after new circle is set, show it
LOOP UNTIL INKEY$ = CHR$(27)
Explanation: The loop is set with _LIMIT to 100 frames per second to limit CPU usage and the speed of the ball. Each loop a circle is drawn while the previous one is erased when the coordinates change. _DISPLAY only shows the new circle position once each loop. The _DISPLAY routine eliminates the need for setting SCREEN swap pages, CLS and PCOPY. _DISPLAY keeps the image off of the screen until the changes have all completed. Drawing 40 circles every loop helps slow down the ball.

Example 2: _DISPLAY must be used to render hardware images placed with _PUTIMAGE (version 1.000 and up).

CONST MenuHeight = 200


SCREEN _NEWIMAGE(640, 480, 32)
'SLEEP 1
LOCATE 20
DO
    _LIMIT 30
    DisplayMenu
    k = _KEYHIT
    IF k <> 0 THEN PRINT k,
LOOP UNTIL k = 32 OR k = 27


SUB DisplayMenu
    STATIC init, MS_HW AS LONG
    IF NOT init THEN
        init = -1
        MS = _NEWIMAGE(640, MenuHeight, 32) 'MenuScreen image
        D = _DEST: _DEST MS
        CLS , &HFFAAAAAA 'background color gray
        _PRINTSTRING (20, 2), "Menu Test" 'image text
        MS_HW = _COPYIMAGE(MS, 33) 'create the MenuScreen_HardWare image
        _FREEIMAGE MS
        _DEST D
    END IF
    _PUTIMAGE (0, 0)-(640, MenuHeight), MS_HW
    _DISPLAY
END SUB
Code adapted by Galleon
Notes: When _DISPLAY is commented out, the hardware Menu Test screen portion will blink and key codes may be seen underneath.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link