home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / POWERMAG / POWER16.MSA / POWER_16 / SCRNSWAP.PWR < prev    next >
Text File  |  1985-11-20  |  5KB  |  107 lines

  1.  
  2.  
  3.                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4.                    ~~ How to perform screen swapping  ~~
  5.                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6.                               BY CHRIS SHARP
  7.  
  8.  
  9.                     When professional programmers start
  10.                     making a new game, one of the first
  11.                     things that they do is to set up a
  12.                    seperate PHYSICAL and LOGICAL screen
  13.                    within the game. The physical screen
  14.                    is the one that you can actually see,
  15.                     while the LOGICAL one stays hidden.
  16.  
  17.                      Using these two screens together,
  18.                    flicker free graphics can be created
  19.                        in even the fastest of games.
  20.  
  21.                     Graphics updates only take place on
  22.                     the LOGICAL screen. This means that
  23.                    you can draw graphics in the LOGICAL
  24.                    screen, and then transfer them to the
  25.                    PHYSICAL screen when a VERTICAL BLANK
  26.                    is occuring. This makes sure that the
  27.                    game player doesn't see the graphics
  28.                    being drawn until they are complete,
  29.                     which means that they wont see any
  30.                              graphics flicker.
  31.  
  32. Consider the following program -:
  33.  
  34. 10 KEY OFF:CURS OFF:HIDE ON:CLICK OFF
  35. 20 FLASH OFF
  36. 30 LOGIC=BACK
  37. 40 SPRITE 1,100,100,1
  38. 50 SCREEN SWAP:WAIT VBL
  39. 60 GOTO 50
  40.  
  41.                     This is a very crude version of the
  42.                      SCREEN SWAP technique, but serves
  43.                             well as an example.
  44.                     Line 30 of the program simply tells
  45.                    the computer not to draw any grahics
  46.                           on the PHYSICAL screen.
  47.                      Line 40 displays a sprite on the
  48.                      screen, providing that there is a
  49.                     sprite bank loaded into STOS memory
  50.                                   bank 1.
  51.                      Although the program will run too
  52.                     quickly for you to notice, you wont
  53.                     see the sprite on the screen until
  54.                    line 50, when the SCREENSWAP command
  55.                      takes place. Normally the sprite
  56.                    would be displayed almost instantly,
  57.                    but in this example we have told STOS
  58.                       not to drawn any sprites on the
  59.                              PHYSICAL screen.
  60.                       The WAIT VBL command in line 50
  61.                     simply makes sure that the graphics
  62.                     operations are performed correctly.
  63.                    Line 60 Simply loops the program back
  64.                                 to line 50.
  65.  
  66.                     Supposing we were to add a movement
  67.                    command to this code. Normally, when
  68.                    we are displaying sprites, AND moving
  69.                    them they tend to flicker. Using the
  70.                      SCREEN SWAPPING technique, we can
  71.                     completely eliminate this flicker,
  72.                     and consequently, the program looks
  73.                                   better.
  74.  
  75.                       Add the following lines to the
  76.                               program above.
  77.  
  78. 45 MOVE X1,"(1,1,100)(1,-1,100)L"
  79. 46 MOVE ON 1
  80.  
  81.                     These 2 lines add animation to the
  82.                     above program. You will notice that
  83.                      because we already have seperate
  84.                     LOGICAL and PHYSICAL screens, that
  85.                     the graphics are smooth. Try taking
  86.                     out the LOGIC=BACK command and the
  87.                    SCREEN SWAP : WAIT VBL commands. You
  88.                     will notice that the graphics have
  89.                      a noticable shudder every now and
  90.                                    then.
  91.  
  92.                    Remember, that before you try typing
  93.                     this program in to the computer, to
  94.                    load a set of sprites into the sprite
  95.                     bank of STOS Basic. If you do not,
  96.                     the screen will simply stay blank.
  97.  
  98.                       To stop the program, press the
  99.                    CONTROL and the C key together. This
  100.                     has the action of halting the code.
  101.                    Now, simply press the UNDO key on the
  102.                     computer TWICE and the screen will
  103.                             be back to normal.
  104.  
  105.  
  106.  
  107.