An animation is a little "movie" made up of several FRAMES.
A typical video is running at 25 frames per second -
that means
there is a new picture on the screen every 1/25 second.
.gif Animations in Web-Pages
A gif animation in a web-page is a small animation that runs "automatically"
in a web-browser.
The file contains several frames that play one after another.
Unfortunately, .gif animations do not run
automatically in Blitz
Basic.
Converting to BMP
In Blitz Basic, an animation must be stored as a "film-strip" in a Windows .bmp file, like the following:
You can use Animation Shop to copy the frames of a .gif animation
and paste them together in Paint-Shop-Pro.
Then save the resulting picture
as a Windows .bmp. Then you are ready to put the animation into
Blitz Basic.
Animations in Blitz Basic
In Blitz Basic, you must use the following commands to run an animation.
They do NOT go all together in one place -
they belong in various places
in the program.
Load the BMP File
killer
= LoadAnimImage("dice.bmp",70,72,0,10)
ani =
0
kx = 700
ky = 300
This means that each frame in the film-strip is 70 x 72 pixels. The
animation starts at the beginning (0), and has 10 frames.
ANI will
be used to count through the frames - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
3 ....
Drawing a Frame
DrawImage killer,kx,ky , ani
ani
= ani + 1
if ani > 9 then ani = 0
Killer is the name assigned in the load opertion. kx and ky
tell the location of the picture.
ANI is the number of the
frame that is displayed (0,1,2...)
ANI = ANI + 1 adds 1 to ANI, so
the next time it will display the next frame.
The if..then.. command
stops the counting after 9 and goes back to the beginning (a LOOP).
Controlling the Speed
The commands above will probably count too fast. Each loop in the game
takes about 1 millisecond,
so the whole animatio will play in 10 milliseconds
- e.g. repeating 100 times per second.
We need to slow this down so it isn't
just a meaningless blur.
DrawImage killer,kx,ky , ani /
10
ani = ani + 1
if ani > 99 then
ani = 0
Now ani is going to count all the way to 99 before repeating. The calculation
ani/10 means it will display
the frames 0.1 , 0.2 , 0.3 , 0.4
, 0.5 , 0.6 ,.... But the computer will truncate these calculations
(that means throw away the decimals) and all of these will display frame
#0. At 1.0 and 1.1 it will go on
to the next frame #1. That means
that each frame lasts 10 game steps before changing. So it runs
10 times slower.
Assignment