'>>> Page 9 of CODE0498.FAQ begins here.
"Spectra.13 was designed specifically for drawing graphics in
QB. It is totally mouse-controlled, has a handy pop-up menu,
features many handy utilities (draw, erase, paint, line, circle,
filled circle, box, filled box, text, Bitmap loading, palette
manipulation, save & load pictures, save & load icons, on-line
help, etc. etc. etc.) It's probably the most comprehensive QB
drawing program available, or at least the best of what I've
seen."
You can find Spectra.13 at http://www.ocis.net/~dshea/qb or, if
you have a question for Dave himself, you can e-mail him at
dshea@mail.ocis.net .
Back to animation.
The first thing you have to do is set aside memory for your
sprite using the DIM command. For example:
DIM Array%(NumberOfElements)
Array% is the name of the array you're using to store the sprite
data. In this section of the FAQ, I won't explain what an array
is. Just think of it as a really big variable that we will use
to store our picture. How do you determine the number of bytes
you need to set aside for this array? It depends on your screen
mode. We will assume SCREEN 13 from now on, in which each pixel
requires exactly one byte of memory. So, to determine the
amount of memory needed, the formula is:
NumberOfElements = ((XValue * YValue) / 2) + 12
The extra 12 bytes are to store the (x,y) dimensions of the
array. You must divide by two because each element of Array%
is an integer value, 16 bytes, and we only need 8. If you don't
understand, don't worry. Just follow the formula.
So where do the XValue and YValue come from? Like I said, a
sprite is a rectangle, so the XValue is the number of pixels
across the sprite horizontally (left to right), and Y is the
number of pixels going up and down. Once you have your graphic
on the screen, try drawing a box around it. Once you have a box
that completely surrounds the graphic, use the X and Y values
for the box as the same for your graphic. If you're having
troubles with this, use the following formula for a box that
completely surrounds your graphic:
LINE (x1, y1) - (x2, y2), 31, B
x = (x2 - x1) : y = (y2 - y1)
Okay, so now I have everything set up, how do I store my picture
in the array? Use the GET command. It's as easy as this:
GET (x1, y1) - (x2, y2), Array%
The x1, y1, x2, and y2 are the exact same as in the LINE command
above, and the array Array% is the one we dimensioned above.
So, now you have the graphic in memory, you can clear the screen
so it's not still on there.
Animation starts here. Once you have all the sprites (or all
the different "frames" of your cartoon) stored in arrays, you
will most likely want to stick them back on the screen at a
certain time in your program. This is done through the PUT
command. For example:
PUT (50, 50), Array%
That will stick the graphic you have in Array% at position
(50, 50) on the screen. Easy as that.
So, now I have this going for me, how do I actually animate?
Basically, you stick your picture on the screen, delay for a
bit so you can see it, erase it, and immediatly stick another
picture on the screen at a different location, and so on. The
one problem with this is that, for a very short time, there is
no picture on the screen. This will cause the animation to
flash a certain amount, no matter how fast your computer is.
There is one way that slightly avoids this problem, but it's not
a complete solution. This will work only if you are using small
sprites, and only if you don't animate near the top of the
a bit, it can also be used in place of a delay loop.) This
command is called the vertical retrace, and it goes like this:
'>>> Page 9 of CODE0498.FAQ ends here. Continued on next page.
___
* SLMR 2.0 * Veni Vedi Velcro: I came, I saw, I stuck around.
--- Maximus/2 3.01
---------------
* Origin: The I.O. Board - 4GB -XX- V34+ (1:2255/10)
|