PDA

View Full Version : using Sprites to display graphics



Tiago
5th March 2009, 16:20
some time ago, i did my first boing ball in C language, using basic draw commands.
i made it in classic red and white, but the system take a lot of time to draw it and fill the color. And if i wanted to pu my ball to "walk from one point to other" i had to draw the full object then erase it all, then draw it again 1 pixel in other direction... this would do a flicker animation....
Can i use sprites to speed up the process?
What limitations do i have?
If i understand correctly a sprite is a small range of pixels that you can put "walking" thru screen using direct hardware.... is that correct? but if i want to use an area bigger then the sprite?

imagine a simple square on screen, with basic commands (no sprites) i can do:

1) draw 4 lines connecting each other
or
2) draw each pixel from one coordenate to other

then to put it going to one side of screen to other, i would have to draw, erase, draw again, erase again....and so one... this will flicker the screen a lot... it works but it is not the best way....


How can i do it with sprites? Must i draw the object inside the sprite area and then i can tell the sprite to "walk" around the screen? But about transparency? if i have a background? :hmmm:

Harrison
5th March 2009, 16:49
Think of a sprite as a 2D graphical bitmap image. The closest thing to explain it easily is to think of a spite like a GIF image. It doesn't need to be drawn by the CPU or graphics hardware in the same way as you have been trying to do in code. Instead it is a set sized image that is held in memory and can be manipulated, moved, scaled etc.

I would recommend you have a play around using AMOS to get a good understanding of sprites and how you can use them. While AMOS isn't the greatest basic programming language it does have a lot of direct support for sprites and the manipulation of them.

There are hardware limitations with sprites. All hardware has a maximum size it can handle to easily move and work with sprites. Coders get around this problem by building larger graphics using multiple sprites on screen and just moving the position of the sprites relative to each other when you want to move them around the screen.

You can also work with transparency within a sprite using something similar to a transparent colour in a gif file, or an alpha channel that removes pixels from the sprite that are a specific pixel colour.

Vector graphics in contrast are completely different. All that exists is the instructions explaining where the start and end points of a vector are on the screen and these end point co-ordinates can be changed to move the vector around the screen. A very different process, and it creates a completely different result.