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 >
Wrap
Text File
|
1993-10-12
|
26KB
|
871 lines
3 SPRITES
3.1 INTRODUCTION
Sprites are small objects that can be moved around the
display without changing the background. The Amiga has eight
DMA channels which allows us to use 8 Hardware Sprites. The
advantages of using hardware sprites is that they can be moved
around, animated etc without interfering with the main
processor (CPU). They are therefore extremely fast to move,
and also very easy to handle.
Sprites can be used in many situations. If you make a game you
can use the sprites as aliens, missiles, explosion etc. Even
now, when you are reading this, a sprite is used. Intuition's
Pointer is actually a sprite as described in chapter 2 WINDOWS.
3.2 LIMITATIONS
Sprites are wonderful small things but there exist some
limitations:
1. Sprites may only be up to 16 pixels wide. (There is no
limit on how tall they may be.) (Sprites are always using
low-resolution pixels. Even if you have a high-resolution
screen, the sprites will only be in low resolution. This
shows how independent sprites are.)
2. Each sprite can only use three colours + one "transparent"
colour.
3. There are only eight hardware sprites.
These limitations can be avoided:
1. You can place two or more sprites side by side in order
to make the object wider than 16 pixels.
2. You can "connect" two sprites and boast the number of
available colours from 3 to 15 plus one transparent.
3. It is possible to reuse each hardware sprite to "plop" out
several sprites (VSprites) on the display.
3.3 COLOURS
Each sprite may have three different colours plus one
transparent colour. Sprite zero and one will use colour
register 16-19, sprite two and three will use colour register
20-23 and so on:
Sprite Colour Register
-----------------------------------
0 and 1 16 - 19 (16 transparent)
2 and 3 20 - 23 (20 -"- )
4 and 5 24 - 27 (24 -"- )
6 and 7 28 - 31 (28 -"- )
Two important thing to remember:
1. The sprites 0 and 1, 2 and 3, 4 and 5, 6 and 7, use the
same colour registers. If you change colour register 17,
both sprite zero and one will be affected.
2. If you have a low-resolution screen with a depth of 5 (32
colours), the last 16 colours will be shared between the
sprites and the screen. However, if you only use a 16
coloured screen (depth 4) you still use the top sixteen
colour registers for the sprites. That means you can have
a 16 coloured screen, and still use another 16 colours for the
sprites.
Colour register 16, 20, 24 and 28 are "transparent" which
means that the background colour of the screen will shine
through. Those registers can have any kind of colours since
they will not affect the sprites.
3.4 ACCESS HARDWARE SPRITES
If you want to use a hardware sprite you need to:
1. Declare and initialize some sprite graphics data.
2. Declare and initialize a SimpleSprite structure.
3. Call the function GetSprite() with a pointer to your
SimpleSprite structure, plus a request for which sprite
you want, as parameters.
4. Move the sprite around by calling the function MoveSprite()
and animate it by changing the sprite graphics
(ChangeSprite()).
5. Return the sprite to the hardware when you do not need it
anymore, by calling the function FreeSprite().
3.4.1 SPRITE DATA
We have already described how to create your own sprite data
in chapter 2 WINDOWS, but here is a short summary:
[A] The first thing you need to do is to draw on a paper how
the sprite should look like. Remember that the sprite may
only be 16 pixels wide, but any height. (You can of course
put two sprites beside each other if you need a sprite
which is wider than 16 pixels). Remember also that you
may only use three colours/sprite (described above).
Imagine that you have come up with a suggestion like this:
0000000110000000 0: Transparent
0000001111000000 1: Red
0000011111100000 2: Yellow
0000111111110000 3: Green
0001111111111000
0011111111111100
0111111111111110
2222222222222222
2222222222222222
0333333333333330
0033333333333300
0003333333333000
0000333333330000
0000033333300000
0000003333000000
0000000330000000
[B] You now need to translate this into Sprite Data. Each
line of the graphics will be translated into two words
of data. The first word represents the first Bitplane,
and the second word the second Bitplane. The idea is that
if you want colour 0 both Bitplane zero and one should be
0, if you want colour 1 Bitplane zero should be 1 and
Bitplane one 0 and so on:
Colour Bitplane One Bitplane Zero Since
----------------------------------------------------------
0 0 0 Binary 00 = Colour 0
1 0 1 " 01 = " 1
2 1 0 " 10 = " 2
3 1 1 " 11 = " 3
The data for the pointer would then look like this:
Bitplane ZERO Bitplane ONE
0000000110000000 0000000000000000
0000001111000000 0000000000000000
0000011111100000 0000000000000000
0000111111110000 0000000000000000
0001111111111000 0000000000000000
0011111111111100 0000000000000000
0111111111111110 0000000000000000
0000000000000000 1111111111111111
0000000000000000 1111111111111111
0111111111111110 0111111111111110
0011111111111100 0011111111111100
0001111111111000 0001111111111000
0000111111110000 0000111111110000
0000011111100000 0000011111100000
0000001111000000 0000001111000000
0000000110000000 0000000110000000
[C] The last step is to translate the binary numbers to type
UWORD. Group the binary number in four and translate it to
Hexadecimal:
Binary Hexadecimal
-------------------
0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
1010 = A
1011 = B
1100 = C
1101 = D
1110 = E
1111 = F
The result will look like this:
ONE: TWO:
------------
0180 0000 0000 0001 1000 0000 0000 0000 0000 0000
03C0 0000 0000 0011 1100 0000 0000 0000 0000 0000
07E0 0000 0000 0111 1110 0000 0000 0000 0000 0000
0FF0 0000 0000 1111 1111 0000 0000 0000 0000 0000
1FF8 0000 0001 1111 1111 1000 0000 0000 0000 0000
3FFC 0000 0011 1111 1111 1100 0000 0000 0000 0000
7FFE 0000 0111 1111 1111 1110 0000 0000 0000 0000
0000 FFFF 0000 0000 0000 0000 1111 1111 1111 1111
0000 FFFF 0000 0000 0000 0000 1111 1111 1111 1111
7FFE 7FFE 0111 1111 1111 1110 0111 1111 1111 1110
3FFC 3FFC 0011 1111 1111 1100 0011 1111 1111 1100
1FF8 1FF8 0001 1111 1111 1000 0001 1111 1111 1000
0FF0 0FF0 0000 1111 1111 0000 0000 1111 1111 0000
07E0 07E0 0000 0111 1110 0000 0000 0111 1110 0000
03C0 03C0 0000 0011 1100 0000 0000 0011 1100 0000
0180 0180 0000 0001 1000 0000 0000 0001 1000 0000
[D] Since the Amiga need to store the position of the sprite,
the size etc, you should also declare two empty words at
the top, and to empty words at the bottom of the Sprite
data. These words will be initialized and maintained by
Intuition, so you do not need to bother about them.
A declaration and initialization of the sprite data would
therefore be:
UWORD chip my_sprite_data[36]=
{
0x0000, 0x0000,
0x0180, 0x0000,
0x03C0, 0x0000,
0x07E0, 0x0000,
0x0FF0, 0x0000,
0x1FF8, 0x0000,
0x3FFC, 0x0000,
0x7FFE, 0x0000,
0x0000, 0xFFFF,
0x0000, 0xFFFF,
0x7FFE, 0x7FFE,
0x3FFC, 0x3FFC,
0x1FF8, 0x1FF8,
0x0FF0, 0x0FF0,
0x07E0, 0x07E0,
0x03C0, 0x03C0,
0x0180, 0x0180,
0x0000, 0x0000
};
IMPORTANT! Remember that all image data must as (always!) be
loaded into the Chip memory (the lowest 512k