Documentation added
This commit is contained in:
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 Tijmen van Nesselrooij
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
44
README.md
Normal file
44
README.md
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# animatedsprite for SFML
|
||||||
|
This is a (stupid) simple implementation of sprite animation for [SFML](https://www.sfml-dev.org/index.php). 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:
|
||||||
|
- `frame-origin x y`
|
||||||
|
- Where `x` and `y` are unsigned integers.
|
||||||
|
- Where is the first sprite frame located in the spritesheet.
|
||||||
|
- `frame-size x y`
|
||||||
|
- Where `x` and `y` are unsigned integers.
|
||||||
|
- How big is the sprite frame.
|
||||||
|
- `frame-step x y`
|
||||||
|
- Where `x` and `y` are 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.
|
||||||
|
- `frame-margin x y`
|
||||||
|
- Where `x` and `y` are unsigned integers.
|
||||||
|
- Represents the "empty space" between frames. A lot of spritesheets come with empty space between each sprite frame. This is to prevent frames bleeding into each other.
|
||||||
|
- `frame-count n`
|
||||||
|
- Where `n` is an unsigned integer.
|
||||||
|
- `frame-time n`
|
||||||
|
- Where `n` is an unsigned integer and represents milliseconds.
|
||||||
|
- `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:
|
||||||
|
```cpp
|
||||||
|
unsigned const x = frameOrigin.x + (frameNumber * frameMargin.x) + (frameNumber * frameStep.x);
|
||||||
|
unsigned const y = frameOrigin.y + (frameNumber * frameMargin.y) + (frameNumber * frameStep.y);
|
||||||
|
```
|
||||||
|
Where x and y are the topleft coordinates of the sprite frame.
|
||||||
Reference in New Issue
Block a user