Difference between revisions of "GET (graphics statement)"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
Line 18: Line 18:
  
  
 +
''Example:'' How to use GET and PUT to move a sprite with the arrow keys.
 +
{{CodeStart}} '' ''
 +
{{Cl|DEFINT}} A-Z
 +
{{Cl|DIM}} BG(300), Box(300), SC(127) ' BG holds background images. Box holds the Box image.
 +
{{Cl|SCREEN (statement)|SCREEN}} 13 ' graphic coordinate minimums are 0 to 319 column or 199 row maximums.
 +
            ' set up screen background
 +
  {{Cl|COLOR}} 4: {{Cl|LOCATE}} 10, 5: {{Cl|PRINT}} "Multikey Keyboard input routine"
 +
  {{Cl|COLOR}} 10: {{Cl|LOCATE}} 12, 4: {{Cl|PRINT}} "Use the arrow keys to move the box."
 +
  {{Cl|LOCATE}} 13, 4: {{Cl|PRINT}} "Note that you can press two or more"
 +
  {{Cl|LOCATE}} 14, 4: {{Cl|PRINT}} "keys at once for diagonal movement!"
 +
  {{Cl|COLOR}} 14: {{Cl|LOCATE}} 16, 4: {{Cl|PRINT}} " Also demonstrates how {{Cl|GET (graphics statement)|GET}} and PUT "
 +
  {{Cl|LOCATE}} 17, 4: {{Cl|PRINT}} "are used to preserve the background."
 +
  {{Cl|COLOR}} 11: {{Cl|LOCATE}} 20, 11: {{Cl|PRINT}} "Press [Esc] to quit"
 +
  x = 150: y = 50: PX = x: PY = y ' actual box starting position
 +
 +
{{Cl|GET (graphics statement)|GET}} (x, y)-(x + 15, y + 15), BG  ' {{Cl|GET (graphics statement)|GET}} original BG at start box position
 +
{{Cl|LINE}} (x, y)-(x + 15, y + 15), 9, BF ' the plain blue box to move
 +
{{Cl|GET (graphics statement)|GET}} (x, y)-(x + 15, y + 15), Box  ' {{Cl|GET (graphics statement)|GET}} to Box Array
 +
 +
{{Cl|DO...LOOP|DO}}  'main loop
 +
  t! = {{Cl|TIMER}} + .05
 +
  {{Cl|DO...LOOP|DO}}        ' 1 Tick (1/18th second) keypress scancode read loop
 +
    a$ = {{Cl|INKEY$}} ' So the keyboard buffer won't get full
 +
    code% = {{Cl|INP}}({{Cl|&H}}60) ' Get keyboard scan code from port 96
 +
    {{Cl|IF...THEN|IF}} code% < 128 {{Cl|THEN}} SC(code%) = 1 {{Cl|ELSE}} SC(code% - 128) = 0 'true/false values to array
 +
  {{Cl|LOOP}} {{Cl|UNTIL}}  {{Cl|TIMER}} > t!' loop until one tick has passed
 +
 +
  PX = x: PY = y  ' previous coordinates
 +
  {{Cl|IF...THEN|IF}} SC(75) = 1 {{Cl|THEN}} x = x - 5: {{Cl|IF...THEN|IF}} x < 0 {{Cl|THEN}} x = 0
 +
  {{Cl|IF...THEN|IF}} SC(77) = 1 {{Cl|THEN}} x = x + 5: {{Cl|IF...THEN|IF}} x > 304 {{Cl|THEN}} x = 304
 +
  {{Cl|IF...THEN|IF}} SC(72) = 1 {{Cl|THEN}} y = y - 5: {{Cl|IF...THEN|IF}} y < 0 {{Cl|THEN}} y = 0
 +
  {{Cl|IF...THEN|IF}} SC(80) = 1 {{Cl|THEN}} y = y + 5: {{Cl|IF...THEN|IF}} y > 184 {{Cl|THEN}} y = 184
 +
  {{Cl|IF...THEN|IF}} x <> PX {{Cl|OR (boolean)|OR}} y <> PY {{Cl|THEN}}            ' look for a changed coordinate value
 +
    {{Cl|WAIT}} 936, 8: {{Cl|PUT (graphics statement)|PUT}}(PX, PY), BG, {{Cl|PSET}}  ' replace previous BG first
 +
    {{Cl|GET (graphics statement)|GET}} (x, y)-(x + 15, y + 15), BG      ' {{Cl|GET (graphics statement)|GET}} BG at new position before box is set
 +
    {{Cl|PUT (graphics statement)|PUT}}(x, y), Box, {{Cl|PSET}}                ' PUT box image at new position
 +
  {{Cl|END IF}}
 +
{{Cl|LOOP}} {{Cl|UNTIL}} SC(1) = 1 ' main loop until [Esc] key (scan code 1) is pressed '' ''
 +
{{CodeEnd}}
  
  
Line 25: Line 64:
 
[[BSAVE]], [[BLOAD]], [[PUT (graphics statement)|PUT]]
 
[[BSAVE]], [[BLOAD]], [[PUT (graphics statement)|PUT]]
  
[[Scancodes]](Example 3), [[Creating Sprite Masks]]
+
[[Scancodes]], [[Creating Sprite Masks]]
  
 
[[Bitmaps]]
 
[[Bitmaps]]

Revision as of 05:41, 27 December 2010

The GET statement is used in graphics to store a box area image of the screen into an INTEGER array.


QB Syntax: GET (column1, row1)-(column2, row2), Array(index)
QB64 Syntax: GET (column1, row1)-(column2, row2), {imagehandle| Array(index)}


  • Do NOT use coordinates off the screen in Qbasic! See the SCREEN (statement) for graphic screen dimensions.
  • QB64 GET statements can use coordinates off of the screen.
  • The GET box coordinates are set just like a LINE box statement is placed. You can use a box to find the correct GET area.
  • INTEGER Array sizes must be large enough to hold the data or an error will occur!
  • To GET more than one image to the same array, designate a unique indexed array area.
  • RGB color settings can be embedded(indexed) at the beginning of the array for custom colors.
  • SCREEN 12 can only GET 1/3 of a fullscreen image (this might not apply for QB64). Rows would incriment 160 for each GET. Once GET has placed the pixel image data in the array, BSAVE it in a loop for SCREEN 12.
  • Once the image is stored in an array PUT can be used to place the image on the screen.


Example: How to use GET and PUT to move a sprite with the arrow keys.

DEFINT A-Z DIM BG(300), Box(300), SC(127) ' BG holds background images. Box holds the Box image. SCREEN 13 ' graphic coordinate minimums are 0 to 319 column or 199 row maximums. ' set up screen background COLOR 4: LOCATE 10, 5: PRINT "Multikey Keyboard input routine" COLOR 10: LOCATE 12, 4: PRINT "Use the arrow keys to move the box." LOCATE 13, 4: PRINT "Note that you can press two or more" LOCATE 14, 4: PRINT "keys at once for diagonal movement!" COLOR 14: LOCATE 16, 4: PRINT " Also demonstrates how GET and PUT " LOCATE 17, 4: PRINT "are used to preserve the background." COLOR 11: LOCATE 20, 11: PRINT "Press [Esc] to quit" x = 150: y = 50: PX = x: PY = y ' actual box starting position GET (x, y)-(x + 15, y + 15), BG ' GET original BG at start box position LINE (x, y)-(x + 15, y + 15), 9, BF ' the plain blue box to move GET (x, y)-(x + 15, y + 15), Box ' GET to Box Array DO 'main loop t! = TIMER + .05 DO ' 1 Tick (1/18th second) keypress scancode read loop a$ = INKEY$ ' So the keyboard buffer won't get full code% = INP(&H60) ' Get keyboard scan code from port 96 IF code% < 128 THEN SC(code%) = 1 ELSE SC(code% - 128) = 0 'true/false values to array LOOP UNTIL TIMER > t!' loop until one tick has passed PX = x: PY = y ' previous coordinates IF SC(75) = 1 THEN x = x - 5: IF x < 0 THEN x = 0 IF SC(77) = 1 THEN x = x + 5: IF x > 304 THEN x = 304 IF SC(72) = 1 THEN y = y - 5: IF y < 0 THEN y = 0 IF SC(80) = 1 THEN y = y + 5: IF y > 184 THEN y = 184 IF x <> PX OR y <> PY THEN ' look for a changed coordinate value WAIT 936, 8: PUT(PX, PY), BG, PSET ' replace previous BG first GET (x, y)-(x + 15, y + 15), BG ' GET BG at new position before box is set PUT(x, y), Box, PSET ' PUT box image at new position END IF LOOP UNTIL SC(1) = 1 ' main loop until [Esc] key (scan code 1) is pressed


See also:

BSAVE, BLOAD, PUT

Scancodes, Creating Sprite Masks

Bitmaps



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