Wasn’t really sure what to call this. But while working on a map editor in blitzmax I came across the need to easily import animations while working on maps. One of the biggest pains of creating assets for the blitz languages is creating animations. This little collection of types will offset a bit of the effort onto the program itself rather than you putting image strips together in some image editor.
The Zip file contains the source and a folder called ‘test’ that shows some of the functionality of this module.
Download: Animation Compiler
The basic API functions are:
- StitchImageFiles:EDAnimStrip(filePath:string)
- StitchFiles:EDAnimStrip(filePath:string)
- GetCompositeStrip:TImage(animImage:TImage, frames:int)
Documentation:
StitchImageFiles:EDAnimStrip(filePath:String)
– Parameter: filePath:String
You must pass a filePath where the file ends in this format:
imageFileBaseName****#.ext_
Where “imageFileBaseName” can be anything as long as it does not contain an underscore. This is then followed by an underscore and then a number, and finally the file format. The number is important as it determines what the stitcher will consider to be the first frame of animation in the given folder. It will look for all files with the same base name and a frame number of equal or greater value than the initial given one.
For example, if I had a folder with images called myImage_00.png, myImage_01.png, and so on all the way to myImage_2300.png that is potentially 2301 frames of animation! I can call the above function like this
[blitzmax]
local strip:EDAnimStrip = EDAnimStitcher.StichImageFiles(“myImage_2250.png”)
[/blitzmax]
and the stitcher will start with image number 2250 and continue til 2300. Pretty simple really.
– Returns:
an EDAnimStrip object or null if the process failed.
StitchFiles:EDAnimStrip(filePath:String)
– Parameter: filePath:String
Same usage as ‘StitchImageFiles'.
example:
[blitzmax]
local imgStrip:EDAnimStrip = EDAnimStitcher.StitchImageFiles(“myImage_00.png”)
[/blitzmax]
GetCompositeStrip:TImage(animImage:TImage, frames:int)
– Parameter: animImage:Timage
the TImage object that holds the animation in blitzmax.
– Parameter: frames:int
total number of frames this animation contains.
– Returns:
a single frame image holding all the animation cells ready to draw or saved to file.
– Example:
[blitzmax] local animstitch:EDAnimStitcher = new EDAnimStitcher local strip:EDAnimStrip = animstitch.StitchFiles(“myImage_2250.png”) local animImg:TImage = imgStrip.getImage() local frames:int = imgStrip.getFrames() local fullImage:TImage = animstitch.GetCompositeStrip(animImg, frames) SavePixmapPNG(fullImage,”myAnimationStrip.png”)
[/blitzmax]
Example uses:
1. Load an image animation sequence from a folder [blitzmax] local as:EDAnimStitcher = new EDAnimStitcher local imgStrip:EDAnimStrip = as.StitchFiles(“myImages/mypicture_00.png”) local myImage:TImage = imgStrip.getImage() local frames:int = imgStrip.getFrames()
[/blitzmax]
2. Same result as above just slighty more condensed syntax [blitzmax] local imgStrip:EDAnimStrip = EDAnimStitcher.StitchImageFiles(“myImages/myImage_00.png”) local myImage:TImage = imgStrip.getImage() local frames:int = imgStrip.getFrames()
[/blitzmax]
…And that’s it! There’s a few more methods you might find useful (such as copyFrames), but you can look at the source ;).
Any bugs, comments, or questions please leave a comment or e-mail me.
– Alex