animatedsprite for SFML
This is a (stupid) simple implementation of sprite animation for SFML. It contains two files:
- animatedsprite.hpp
- animatedsprite.cpp
And those are all you need to get going. In the
test/directory you find a super small program using the animatedsprite provided utlities.
The Animation File Format
Animation files are just simple ASCII text files. See test/testanimations.txt as an example. Below the structure of each animation definition is described.
Comment lines in the file start with # which are ignored, along with empty lines.
Each animation starts with:
animation MyAnimationName
Followed by a collection of definition lines, which always have a leading single tab:
frame-origin x y- Where
xandyare unsigned integers. - Where is the first sprite frame located in the spritesheet.
- Where
frame-size x y- Where
xandyare unsigned integers. - How big is the sprite frame.
- Where
frame-step x y- Where
xandyare unsigned integers. - How much the frame needs to be translated every new frame.
- Usually identical to your frame-size, but useful for example for skipping every other frame.
- Where
frame-count n- Where
nis an unsigned integer.
- Where
frame-time n- Where
nis an unsigned integer and represents milliseconds.
- Where
reverse- If present it reverse the animation.
loop- If present it loops the animation by going back to the first frame after the last frame has been reached.
bounce- If present it loops the animation by going in reverse whenever the last frame has been reached.
The actual source code tells you most likely all you need to know:
unsigned const x = frameOrigin.x + (frameNumber * frameStep.x);
unsigned const y = frameOrigin.y + (frameNumber * frameStep.y);
Where x and y are the topleft coordinates of the sprite frame.
Languages
C++
98.4%
Makefile
1.6%