Wave's~ BlitzMax Tutorial for NG~ November, 2015 ~ Version 11
Beginners guide to BlitzMax 

Animations
Animations are several images loaded side by side. When you draw your Animation Image you choose which frame you want to draw. In this way you can with ease draw animations in your game. This is not tricky at all. When you load an animation you need one image containing all your animation frames. It is also required that all these frames have the same size. Let's say you have an explosion 50x50 with 25 frames.
LoadAnimImage("Path$,width,height,start,count")
'Frames "start" at 0 for the first image, while "count" has to be at least 1, (at least 1 frame).
 
'To load this image as an animation you can do as follows:
My_Animation = LoadAnimImage("/Gfx/Image.bmp",25,25,0,24)
DrawImage(My_Animation,X,Y,Frame)
In DrawImage, "frame" goes from 0 to your frame "count", which is what you set it to in LoadAnimImage.
 
If you haven't already, go to any paint program you have, throw together a series of pictures side by side. Create an image 250 width x 50 height. Try to use the grid tool or rulers to draw five 50x50 pictures side by side. Try to make it an animation of some sort, perhaps an explosion? 5 frames isn't much but it gives you a good start to work with. Now setup a .bmx file in the same directory as your newly saved animation. I recommend .png as a good format as it is smaller in file-size than a .bmp but it does not distort your image at compression as a .jpg does.
 
You can use the example code at the bottom of this page to test your animation.
 
First let's check out IncBin.

Save images in your executable (exe)
BlitzMax has a handy function to pack all your multimedia in your exe when you compile. This allows you to supply your game as an exe only. This means that no additional files will be required to play it. It also protects your art from others (not hack proof). And its function is very easy to use.

To include a file put this code somewhere at the start of your file:
Incbin "directory/filename.bmp"
 
'Then when you load your images write:
LoadImage( "incbin::directory/filename.bmp")
The path can be in sub directories if you like, just refer to the same path when you loaded it with Incbin. Note: When you LoadImage using incbin:: make sure you spell incbin with small letters only! It's sensitive! When you incbin an image, "MyImage.png", the complier will tell you if the image is not found.

Animation Example, including incbin. Make sure you always Loadimages after Graphics!
Strict
Incbin "ExplosionTest.png"
Global Explode = False
Global X = 50, Y = 50
Local Frame = 0, XTimes = 0
 
Graphics 800,600,0
 
SetMaskColor 255,255,255 ' White
Global My_Animation:Timage=LoadAnimImage("ExplosionTest.png",50,50,0,5)
If My_Animation = Null Then
  DebugLog
"Image could Not load - Check pathAnd filename"
  End
End If

 
Repeat
  Cls
  If Explode = True
    DrawImage(My_Animation,X,Y,Frame)
    Frame:+1
    If Frame = 5 Then
      Frame =
0
      XTimes:+
1
    End If
    If XTimes > 25 Then
      Explode = False
      XTimes = 0
    End If
  End If
 
  'Explode at Mouse Left Click
  If KeyHit(1)
    Explode = True
    X = MouseX()
    Y =
MouseY()
    Frame = 0
  End If
  Flip
Until KeyDown(Key_Escape)
 
To Index | Next Page page 20