1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130# raylib-aseprite
Load [Aseprite](https://www.aseprite.org) `.aseprite` and `.ase` files for animated sprites in [raylib](https://www.raylib.com).


## Features
- Load [Aseprite](https://www.aseprite.org/) files directly for use in raylib
- Draw individual frames
- Load and draw [Aseprite tags](https://www.aseprite.org/docs/tags/) as sprite animations
- Support for Forwards, Backwards, and Ping-Pong animations
- Adjust tag animation speed by using `tag.speed`
- Pause tag animations by using `tag.pause`
- Toggle whether animations will continue when they finish with `tag.loop`
- Load [Aseprite slice](https://www.aseprite.org/docs/slices/) rectangles for collisions and bounds
## Usage
This is a header-only library. To use it, define `RAYLIB_ASEPRITE_IMPLEMENTATION` in one .c source file before including [*raylib-aseprite.h*](include). You will also have to link the raylib dependency.
### Example
The below is a basic example, see the [examples](examples) folder for more.
``` c
#include "raylib.h"
#define RAYLIB_ASEPRITE_IMPLEMENTATION
#include "raylib-aseprite.h"
int main() {
InitWindow(640, 480, "Aseprite Example");
// Load the George Aseprite file.
Aseprite george = LoadAseprite("resources/george.aseprite");
// Load the Walk Down tag.
AsepriteTag walkdown = LoadAsepriteTag(george, "Walk-Down");
walkdown.speed = 2; // Double the animation speed.
while(!WindowShouldClose()) {
// Update the animation frame.
UpdateAsepriteTag(&walkdown);
BeginDrawing();
{
ClearBackground(RAYWHITE);
// Draw the first frame from the George sprite.
DrawAseprite(george, 0, 100, 100, WHITE);
// Draw the Walk Down animation.
DrawAsepriteTag(walkdown, 200, 100, WHITE);
}
EndDrawing();
}
// Clean up the George aseprite.
UnloadAseprite(george);
CloseWindow();
return 0;
}
```
See the [examples directory](examples) for more demonstrations of how to use *raylib-aseprite*.
### API
``` c
// Aseprite functions
Aseprite LoadAseprite(const char* fileName); // Load an .aseprite file
Aseprite LoadAsepriteFromMemory(unsigned char* fileData, int size); // Load an aseprite file from memory
bool IsAsepriteValid(Aseprite aseprite); // Check if the given Aseprite was loaded successfully
void UnloadAseprite(Aseprite aseprite); // Unloads the aseprite file
void TraceAseprite(Aseprite aseprite); // Display all information associated with the aseprite
Texture GetAsepriteTexture(Aseprite aseprite); // Retrieve the raylib texture associated with the aseprite
int GetAsepriteWidth(Aseprite aseprite); // Get the width of the sprite
int GetAsepriteHeight(Aseprite aseprite); // Get the height of the sprite
void DrawAseprite(Aseprite aseprite, int frame, int posX, int posY, Color tint);
void DrawAsepriteV(Aseprite aseprite, int frame, Vector2 position, Color tint);
void DrawAsepriteEx(Aseprite aseprite, int frame, Vector2 position, float rotation, float scale, Color tint);
void DrawAsepritePro(Aseprite aseprite, int frame, Rectangle dest, Vector2 origin, float rotation, Color tint);
// Aseprite Tag functions
AsepriteTag LoadAsepriteTag(Aseprite aseprite, const char* name); // Load an Aseprite tag animation sequence
AsepriteTag LoadAsepriteTagFromIndex(Aseprite aseprite, int index); // Load an Aseprite tag animation sequence from its index
int GetAsepriteTagCount(Aseprite aseprite); // Get the total amount of available tags
bool IsAsepriteTagValid(AsepriteTag tag); // Check if the given Aseprite tag was loaded successfully
void UpdateAsepriteTag(AsepriteTag* tag); // Update the tag animation frame
AsepriteTag GenAsepriteTagDefault(); // Generate an empty Tag with sane defaults
void DrawAsepriteTag(AsepriteTag tag, int posX, int posY, Color tint);
void DrawAsepriteTagV(AsepriteTag tag, Vector2 position, Color tint);
void DrawAsepriteTagEx(AsepriteTag tag, Vector2 position, float rotation, float scale, Color tint);
void DrawAsepriteTagPro(AsepriteTag tag, Rectangle dest, Vector2 origin, float rotation, Color tint);
// Aseprite Slice functions
AsepriteSlice LoadAsepriteSlice(Aseprite aseprite, const char* name); // Load a slice from an Aseprite based on its name.
AsepriteSlice LoadAsperiteSliceFromIndex(Aseprite aseprite, int index); // Load a slice from an Aseprite based on its index.
int GetAsepriteSliceCount(Aseprite aseprite); // Get the amount of slices that are defined in the Aseprite.
bool IsAsepriteSliceValid(AsepriteSlice slice); // Return whether or not the given slice was found.
AsepriteSlice GenAsepriteSliceDefault(); // Generate empty Aseprite slice data.
```
## Similar Solutions
- [Nayanim](https://github.com/VaguinerG/nayanim) - Animation Extension for Nim's Raylib, by [VaguinerG](https://github.com/VaguinerG)
## Development
To build the example locally, and run tests, use [cmake](https://cmake.org/).
``` bash
git submodule update --init
mkdir build
cd build
cmake ..
make
cd examples
./raylib-aseprite-example
```
This uses [cute_aseprite.h](https://github.com/RandyGaul/cute_headers/blob/master/cute_aseprite.h) to handle loading the aseprite file. Thank you to [Randy Gaul's cute_headers](https://github.com/RandyGaul/cute_headers) for making this all possible.
## License
*raylib-aseprite* is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details.