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

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

   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 immediately 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
   screen.  Add the following line AFTER you have placed your
   sprite, but BEFORE you erase it.  (As it slows down the program
   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:

       WAIT 986, 8    (or WAIT &H3DA, 8....)

   That will help, but only a little bit.  The following example is
   a little animation of a guy running, and it uses the techniques
   described above.

[begin]
   ' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
   ' RUN.BAS  by  Dave Shea
   ' Released to Public Domain on January 18th, 1997.
   '
   ' Compile: MicroSoft QuickBasic 4.5, PDS 7.1
   '
   ' Desc: A simple animation. Demonstrates some techniques behind
   ' animating in QB.
   '
   ' (Use at your own risk)
   ' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

   CLS : SCREEN 13               'Set Screen 13, of course!


   PSET (25, 71), 31: DRAW "rdld2l2ngr3fnehld3rfrdngulhlg2lh"
   PSET (45, 71), 31: DRAW "rdld2lgnder2dnr2ld2rfdnguhld2lg"
   PSET (65, 71), 31: DRAW "rdld2ldrnednrddrfndhldlg"
   PSET (85, 71), 31: DRAW "rdld2lgnderdnr2d2rfdnguhlgdl2"

                                 'The above will draw four
                                 'different frames of a Stick man
                                 'running.

   DIM Guy1%(134), Guy2%(134), Guy3%(134), Guy4%(134)

                                 'Set aside the memory required for
                                 'each frame.

   GET (16, 69)-(34, 82), Guy1%  'Stick each frame into memory
   GET (36, 69)-(54, 82), Guy2%  '(X and Y values calculated by
   GET (56, 69)-(74, 82), Guy3%  ' pure trial and error. =u)
   GET (76, 69)-(94, 82), Guy4%

   CLS                           'Guess what THIS does!

   FOR a = 1 TO 300 STEP 2                'Begin Loop
    b = b + 1: IF b = 5 THEN b = 1        'Increase b until it
                                          'reaches a value of 5,
                                          'reset it to 1

    IF b = 1 THEN PUT (a, 100), Guy1%     'Determine which frame to
    IF b = 2 THEN PUT (a, 100), Guy2%     'PUT, then PUT it.
    IF b = 3 THEN PUT (a, 100), Guy3%
    IF b = 4 THEN PUT (a, 100), Guy4%

    WAIT 986, 8                           'Wait for Vertical
                                          'Retrace

    Start = TIMER                         'Small delay loop to slow
    WHILE TIMER < Start + .1: WEND        'it down a bit.

    IF b = 1 THEN PUT (a, 100), Guy1%     'Erase current frame by
    IF b = 2 THEN PUT (a, 100), Guy2%     'PUTting it again.

    IF b = 3 THEN PUT (a, 100), Guy3%
    IF b = 4 THEN PUT (a, 100), Guy4%

   NEXT                                   'Loop!
[end]

'>>> Page  13  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™.