Difference between revisions of "DISPLAY"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 10: Line 10:
* Call _DISPLAY each time the screen graphics are to be displayed.  
* Call _DISPLAY each time the screen graphics are to be displayed.  
* Re-enable the automatic display by calling [[_AUTODISPLAY]].
* Re-enable the automatic display by calling [[_AUTODISPLAY]].
* _DISPLAY can often replace page flipping and [[PCOPY]]!




{{PageExamples}}
''Examples:'' Displaying a circle bouncing around the screen.
{{CodeStart}}
{{CodeStart}}


{{Cl|SCREEN (statement)|SCREEN}} 13, 0, 1, 0
{{Cl|SCREEN (statement)|SCREEN}} 13


dx = 1: dy = 1
dx = 1: dy = 1
{{Cl|DO}}
{{Cl|DO}}
    {{Cl|PCOPY}} 1,0
    {{Cl|CLS}}
     {{Cl|_LIMIT}} 60 ' set to 60 frames per second
     {{Cl|_LIMIT}} 60 ' set to 60 frames per second
     x = x + dx: y = y + dy
     x = x + dx: y = y + dy
     {{Cl|IF...THEN|IF}} x < 0 {{Cl|OR}} x > 320 {{Cl|THEN}} dx = -dx
     {{Cl|IF...THEN|IF}} x < 0 {{Cl|OR}} x > 320 {{Cl|THEN}} dx = -dx 'limit columns
     {{Cl|IF...THEN|IF}} y < 0 {{Cl|OR}} y > 200 {{Cl|THEN}} dy = -dy
     {{Cl|IF...THEN|IF}} y < 0 {{Cl|OR}} y > 200 {{Cl|THEN}} dy = -dy 'limit rows
     {{Cl|CIRCLE}} (x, y), 10, 15
    IF px <> x OR py <> y THEN CIRCLE (px, py), 10, 0  'erase old circle with black one
     {{Cl|_DISPLAY}}
     {{Cl|CIRCLE}} (x, y), 10, 14
    px = x: py = y  'save older coordinates to erase older circle next loop
     {{Cl|_DISPLAY}} 'after new cicle is set, show it
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = CHR$(27)
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = CHR$(27)


{{CodeEnd}}
{{CodeEnd}}
:Displays a circle going around the screen at 60 frames per second, displaying each frame to the screen.
 
:''Explanation:'' The loop is set with [[_LIMIT]] to 60 frames per second to limit CPU usage. 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. This routine eliminates the need for setting [[SCREEN (statement)]] pages, [[CLS]] and [[PCOPY]].




{{PageSeeAlso}}
{{PageSeeAlso}}
* {{KW|_AUTODISPLAY}}
* {{KW|_AUTODISPLAY}}
* {{KW|_SCREEN (statement)|SCREEN}}
* {{KW|PCOPY}}




{{PageNavigation}}
{{PageNavigation}}

Revision as of 05:16, 10 July 2010

The _DISPLAY statement turns off the automatic display of the screen graphics (which is at around 30 fps) while displaying the screen graphics.


Syntax

_DISPLAY


Description

  • _DISPLAY turns off the default _AUTODISPLAY when used.
  • Call _DISPLAY each time the screen graphics are to be displayed.
  • Re-enable the automatic display by calling _AUTODISPLAY.


Examples: Displaying a circle bouncing around the screen.

SCREEN 13 dx = 1: dy = 1 DO _LIMIT 60 ' set to 60 frames per second x = x + dx: y = y + dy IF x < 0 OR x > 320 THEN dx = -dx 'limit columns IF y < 0 OR y > 200 THEN dy = -dy 'limit rows IF px <> x OR py <> y THEN CIRCLE (px, py), 10, 0 'erase old circle with black one CIRCLE (x, y), 10, 14 px = x: py = y 'save older coordinates to erase older circle next loop _DISPLAY 'after new cicle is set, show it LOOP UNTIL INKEY$ = CHR$(27)

Explanation: The loop is set with _LIMIT to 60 frames per second to limit CPU usage. 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. This routine eliminates the need for setting SCREEN (statement) pages, CLS and PCOPY.


See also



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page