home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / cmanual-3.0.lha / CManual / Graphics / Sprites / Sprites.doc < prev    next >
Text File  |  1993-10-12  |  26KB  |  871 lines

  1. 3    SPRITES
  2.  
  3. 3.1  INTRODUCTION
  4.  
  5. Sprites are small objects that can be moved around the
  6. display without changing the background. The Amiga has eight
  7. DMA channels which allows us to use 8 Hardware Sprites. The
  8. advantages of using hardware sprites is that they can be moved
  9. around, animated etc without interfering with the main
  10. processor (CPU). They are therefore extremely fast to move,
  11. and also very easy to handle.
  12.  
  13. Sprites can be used in many situations. If you make a game you
  14. can use the sprites as aliens, missiles, explosion etc. Even
  15. now, when you are reading this, a sprite is used. Intuition's
  16. Pointer is actually a sprite as described in chapter 2 WINDOWS.
  17.  
  18.  
  19.  
  20. 3.2  LIMITATIONS
  21.  
  22. Sprites are wonderful small things but there exist some
  23. limitations:
  24.  
  25. 1. Sprites may only be up to 16 pixels wide. (There is no
  26.    limit on how tall they may be.) (Sprites are always using
  27.    low-resolution pixels. Even if you have a high-resolution
  28.    screen, the sprites will only be in low resolution. This
  29.    shows how independent sprites are.)
  30.  
  31. 2. Each sprite can only use three colours + one "transparent"
  32.    colour.
  33.  
  34. 3. There are only eight hardware sprites. 
  35.  
  36. These limitations can be avoided:
  37.  
  38. 1. You can place two or more sprites side by side in order
  39.    to make the object wider than 16 pixels.
  40.  
  41. 2. You can "connect" two sprites and boast the number of
  42.    available colours from 3 to 15 plus one transparent.
  43.  
  44. 3. It is possible to reuse each hardware sprite to "plop" out
  45.    several sprites (VSprites) on the display.
  46.  
  47.  
  48.  
  49. 3.3  COLOURS
  50.  
  51. Each sprite may have three different colours plus one
  52. transparent colour. Sprite zero and one will use colour
  53. register 16-19, sprite two and three will use colour register
  54. 20-23 and so on:
  55.  
  56. Sprite    Colour Register
  57. -----------------------------------
  58. 0 and 1   16 - 19  (16 transparent)
  59. 2 and 3   20 - 23  (20     -"-    )
  60. 4 and 5   24 - 27  (24     -"-    )
  61. 6 and 7   28 - 31  (28     -"-    )
  62.  
  63. Two important thing to remember:
  64.  
  65. 1. The sprites 0 and 1, 2 and 3, 4 and 5, 6 and 7, use the
  66.    same colour registers. If you change colour register 17,
  67.    both sprite zero and one will be affected.
  68.  
  69. 2. If you have a low-resolution screen with a depth of 5 (32
  70.    colours), the last 16 colours will be shared between the
  71.    sprites and the screen. However, if you only use a 16
  72.    coloured screen (depth 4) you still use the top sixteen
  73.    colour registers for the sprites. That means you can have
  74.    a 16 coloured screen, and still use another 16 colours for the
  75.    sprites.
  76.  
  77. Colour register 16, 20, 24 and 28 are "transparent" which
  78. means that the background colour of the screen will shine
  79. through. Those registers can have any kind of colours since
  80. they will not affect the sprites.
  81.  
  82.  
  83.  
  84. 3.4  ACCESS HARDWARE SPRITES
  85.  
  86. If you want to use a hardware sprite you need to:
  87.  
  88. 1. Declare and initialize some sprite graphics data.
  89.  
  90. 2. Declare and initialize a SimpleSprite structure.
  91.  
  92. 3. Call the function GetSprite() with a pointer to your
  93.    SimpleSprite structure, plus a request for which sprite
  94.    you want, as parameters.
  95.  
  96. 4. Move the sprite around by calling the function MoveSprite()
  97.    and animate it by changing the sprite graphics
  98.    (ChangeSprite()).
  99.  
  100. 5. Return the sprite to the hardware when you do not need it
  101.    anymore, by calling the function FreeSprite().
  102.  
  103.  
  104.  
  105. 3.4.1  SPRITE DATA
  106.  
  107. We have already described how to create your own sprite data
  108. in chapter 2 WINDOWS, but here is a short summary:
  109.  
  110. [A] The first thing you need to do is to draw on a paper how
  111.     the sprite should look like. Remember that the sprite may
  112.     only be 16 pixels wide, but any height. (You can of course
  113.     put two sprites beside each other if you need a sprite
  114.     which is wider than 16 pixels). Remember also that you
  115.     may only use three colours/sprite (described above).
  116.     
  117.     Imagine that you have come up with a suggestion like this:
  118.     
  119.     0000000110000000    0: Transparent
  120.     0000001111000000    1: Red
  121.     0000011111100000    2: Yellow
  122.     0000111111110000    3: Green
  123.     0001111111111000
  124.     0011111111111100
  125.     0111111111111110
  126.     2222222222222222
  127.     2222222222222222
  128.     0333333333333330
  129.     0033333333333300
  130.     0003333333333000
  131.     0000333333330000
  132.     0000033333300000
  133.     0000003333000000
  134.     0000000330000000
  135.  
  136.  
  137. [B] You now need to translate this into Sprite Data. Each
  138.     line of the graphics will be translated into two words
  139.     of data. The first word represents the first Bitplane,
  140.     and the second word the second Bitplane. The idea is that
  141.     if you want colour 0 both Bitplane zero and one should be
  142.     0, if you want colour 1 Bitplane zero should be 1 and
  143.     Bitplane one 0 and so on:
  144.  
  145.     Colour  Bitplane One  Bitplane Zero          Since
  146.     ----------------------------------------------------------
  147.     0       0             0               Binary 00 = Colour 0
  148.     1       0             1                  "   01 =    "   1
  149.     2       1             0                  "   10 =    "   2
  150.     3       1             1                  "   11 =    "   3
  151.  
  152.     The data for the pointer would then look like this:
  153.  
  154.     Bitplane ZERO      Bitplane ONE
  155.  
  156.     0000000110000000   0000000000000000
  157.     0000001111000000   0000000000000000
  158.     0000011111100000   0000000000000000
  159.     0000111111110000   0000000000000000
  160.     0001111111111000   0000000000000000
  161.     0011111111111100   0000000000000000
  162.     0111111111111110   0000000000000000
  163.     0000000000000000   1111111111111111
  164.     0000000000000000   1111111111111111
  165.     0111111111111110   0111111111111110
  166.     0011111111111100   0011111111111100
  167.     0001111111111000   0001111111111000
  168.     0000111111110000   0000111111110000
  169.     0000011111100000   0000011111100000
  170.     0000001111000000   0000001111000000
  171.     0000000110000000   0000000110000000
  172.  
  173.  
  174. [C] The last step is to translate the binary numbers to type
  175.     UWORD. Group the binary number in four and translate it to
  176.     Hexadecimal:
  177.  
  178.     Binary  Hexadecimal
  179.     -------------------
  180.     0000 =  0
  181.     0001 =  1
  182.     0010 =  2
  183.     0011 =  3
  184.     0100 =  4
  185.     0101 =  5
  186.     0110 =  6
  187.     0111 =  7
  188.     1000 =  8
  189.     1001 =  9
  190.     1010 =  A
  191.     1011 =  B
  192.     1100 =  C
  193.     1101 =  D
  194.     1110 =  E
  195.     1111 =  F
  196.  
  197.     The result will look like this:
  198.  
  199.     ONE:    TWO:
  200.     ------------
  201.     0180    0000      0000 0001 1000 0000  0000 0000 0000 0000
  202.     03C0    0000      0000 0011 1100 0000  0000 0000 0000 0000
  203.     07E0    0000      0000 0111 1110 0000  0000 0000 0000 0000
  204.     0FF0    0000      0000 1111 1111 0000  0000 0000 0000 0000
  205.     1FF8    0000      0001 1111 1111 1000  0000 0000 0000 0000
  206.     3FFC    0000      0011 1111 1111 1100  0000 0000 0000 0000
  207.     7FFE    0000      0111 1111 1111 1110  0000 0000 0000 0000
  208.     0000    FFFF      0000 0000 0000 0000  1111 1111 1111 1111
  209.     0000    FFFF      0000 0000 0000 0000  1111 1111 1111 1111
  210.     7FFE    7FFE      0111 1111 1111 1110  0111 1111 1111 1110
  211.     3FFC    3FFC      0011 1111 1111 1100  0011 1111 1111 1100
  212.     1FF8    1FF8      0001 1111 1111 1000  0001 1111 1111 1000
  213.     0FF0    0FF0      0000 1111 1111 0000  0000 1111 1111 0000
  214.     07E0    07E0      0000 0111 1110 0000  0000 0111 1110 0000
  215.     03C0    03C0      0000 0011 1100 0000  0000 0011 1100 0000
  216.     0180    0180      0000 0001 1000 0000  0000 0001 1000 0000
  217.  
  218.  
  219. [D] Since the Amiga need to store the position of the sprite,
  220.     the size etc, you should also declare two empty words at
  221.     the top, and to empty words at the bottom of the Sprite
  222.     data. These words will be initialized and maintained by
  223.     Intuition, so you do not need to bother about them.
  224.  
  225.     A declaration and initialization of the sprite data would
  226.     therefore be:
  227.  
  228.     UWORD chip my_sprite_data[36]=
  229.     {
  230.       0x0000, 0x0000,
  231.  
  232.       0x0180, 0x0000,
  233.       0x03C0, 0x0000,
  234.       0x07E0, 0x0000,
  235.       0x0FF0, 0x0000,
  236.       0x1FF8, 0x0000,
  237.       0x3FFC, 0x0000,
  238.       0x7FFE, 0x0000,
  239.       0x0000, 0xFFFF,
  240.       0x0000, 0xFFFF,
  241.       0x7FFE, 0x7FFE,
  242.       0x3FFC, 0x3FFC,
  243.       0x1FF8, 0x1FF8,
  244.       0x0FF0, 0x0FF0,
  245.       0x07E0, 0x07E0,
  246.       0x03C0, 0x03C0,
  247.       0x0180, 0x0180,
  248.       
  249.       0x0000, 0x0000
  250.     };
  251.  
  252.  
  253. IMPORTANT! Remember that all image data must as (always!) be
  254. loaded into the Chip memory (the lowest 512k