z80:Sprites

From Learn @ Cemetech
Jump to: navigation, search

Basic Sprites

If you are tired of using a theta sign to represent people in your games, then it is time for you to learn about sprites. Sprites are basically just pictures. They are moved around the screen or quicky erased and replaced with other sprites to create animations. They are stored in your code just like data. So let's say you are making pong, and your first sprite is going to be the ball that bounces around the screen. First label your sprite. Then you have to draw out your sprite, and I literally mean draw it out. The code below is sprite data for the ball.


   Ball sprite:
   .db	%00111100
   .db	%01111110
   .db	%11111011
   .db	%11111111
   .db	%11111111
   .db	%11111111
   .db	%01111110
   .db	%00111100


No, the code above is not some weird code that will be tricky to learn. It is actually the picture of a ball. In the binary numbers, you place a zero where you want the pixel to be blank, and a 1 where you want it to be filled. So really, I made a ball that looks like this:

Ball.jpg

Placing The Sprite On The Screen.

Splash Screens

If you don't already know, a splash screen is normally the main image shown while loading, or first starting the game. To display this full screen image is quite easy actually. First you must load the picture data into a register. Then you must load plotscreen into a register, then you must switch them.

Advanced Notions

Greyscale sprites require two different buffers. For example, I may want to make a shaded sphere. We need two buffers, the dark buffer (displayed 2/3 of the time) and a light buffer (1/3 of the time). See the page grayscale for more info.

A shaded sphere would be:

Light buffer:
  %00111100
  %01111110
  %10011011
  %10011111
  %10001111
  %11000011
  %01100010
  %00111100
Dark buffer:
  %00111100
  %01000010
  %11100001
  %11100001
  %11110001
  %11111101
  %01111110
  %00111100

While I have not seen the sprite drawn out, it will form what should appear to be a shaded sphere. Draw it out yourself.

Animating Sprites

Now that you know the basics of sprites, then you should no how to animate them. If your sprite is of a human, then just moving the sprite around the screen will not look smooth. What you need is a couple of sprites, one for each position the human would be walking in. Therefore you can make it look like the sprite is actaully walking by just flashing the sprites. Remember that you cant just send the first sprite to the screen, and then send the other. You have to erase the first sprite before displaying the second one. There is a routine in Sprite Routines that you can study.

Scrolling Sprites

Conclusion