TIP: Click on subject to list as thread! ANSI
echo: quik_bas
to: All
from: Greg Easthom
date: 2004-03-15 16:23:22
subject: Code FAQ [12/15

'>>> Page  12  of Code FAQ begins here.


  DEF SEG

END SUB
[end]

11) HOW CAN I ANIMATE SPRITES IN QB?

   First thing, what's a sprite?  Basically, it's a rectangle box
   that has a picture in it.  In something like cartoon animation,
   they would be referred to as frames.  So when you're animating
   in QB, you're essentially doing the same thing that you would do
   if you were to create a cartoon, just on a smaller scale.

   So how do you create sprites?  QB has a variety of graphics
   functions (DRAW, LINE, CIRCLE, PSET, etc.) at your disposal.
   They are quite cumbersome to use, so you might find it difficult
   to get started.  You may want to keep your eyes open for a QB
   graphics editor; there are probably a lot of them.
   Coincidentally (?), Dave Shea has written a graphics program
   for QB:

   "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{at}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:


'>>> Page  12  of Code FAQ ends here. Continued in next message.

 * Brought to you by Greg's Little QBasic Auto-Poster *

--- Maximus 3.01
* Origin: The BandMaster, Vancouver, B.C., Canada (1:153/7715)
SEEN-BY: 633/267 270
@PATH: 153/7715 140/1 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.