Skip to content

Commit 33fd270

Browse files
committed
v1.0.0
1 parent f64423b commit 33fd270

File tree

8 files changed

+109
-32
lines changed

8 files changed

+109
-32
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.11)
22
project (raylib-aseprite
3-
VERSION 0.2.1
3+
VERSION 1.0.0
44
DESCRIPTION "raylib-aseprite"
55
HOMEPAGE_URL "https://github.com/robloach/raylib-aseprite"
66
LANGUAGES C)
@@ -9,7 +9,7 @@ project (raylib-aseprite
99
add_subdirectory(include)
1010

1111
# Examples
12-
option(RAYLIB_ASEPRITE_BUILD_EXAMPLES "Example" ON)
12+
option(RAYLIB_ASEPRITE_BUILD_EXAMPLES "Build Examples" ON)
1313
if(RAYLIB_ASEPRITE_BUILD_EXAMPLES)
1414
add_subdirectory(examples)
1515
endif()

README.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
# raylib-aseprite
22

3-
Load [Aseprite](https://aseprite.org) `.aseprite` files to use animated sprites in [raylib](https://raylib.com).
3+
Load [Aseprite](https://aseprite.org) `.aseprite` files for animated sprites in [raylib](https://raylib.com).
44

55
![examples/raylib-aseprite-example.png](examples/raylib-aseprite-example.png)
66

7+
## Features
8+
9+
- Load [Aseprite](https://www.aseprite.org/) files directly for use in raylib
10+
- Draw individual frames
11+
- Load and draw [Aseprite tags](https://www.aseprite.org/docs/tags/) as sprite animations
12+
- Support for Forwards, Backwards, and Ping-Pong animations
13+
- Adjust tag animation speed by using `tag.speed`
14+
- Pause tag animations by using `tag.pause`
15+
- Toggle whether animations will continue when they finish with `tag.loop`
16+
717
## Usage
818

9-
This is a header-only library. To use it, define `RAYLIB_ASEPRITE_IMPLEMENTATION` in one .c source file before including *raylib-aseprite.h*. You will also have to link the raylib dependency.
19+
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.
1020

1121
### Example
1222

@@ -19,37 +29,40 @@ This is a header-only library. To use it, define `RAYLIB_ASEPRITE_IMPLEMENTATION
1929
int main() {
2030
InitWindow(640, 480, "Aseprite Example");
2131

22-
// Load the backpacker Aseprite file.
23-
Aseprite backpacker = LoadAseprite("resources/backpacker.aseprite");
32+
// Load the George Aseprite file.
33+
Aseprite george = LoadAseprite("resources/george.aseprite");
2434

2535
// Load the Walk Down tag.
26-
AsepriteTag walkdown = LoadAsepriteTag(backpacker, "Walk Down");
36+
AsepriteTag walkdown = LoadAsepriteTag(george, "Walk-Down");
2737
walkdown.speed = 2; // Double the animation speed.
2838

2939
while(!WindowShouldClose()) {
30-
// Update the animation frame for walk down.
40+
// Update the animation frame.
3141
UpdateAsperiteTag(&walkdown);
3242

3343
BeginDrawing();
34-
ClearBackground(RAYWHITE);
44+
{
45+
ClearBackground(RAYWHITE);
3546

36-
// Draw the 0th frame from the backpacker sprite.
37-
DrawAseprite(backpacker, 0, 100, 100, WHITE);
38-
39-
// Draw the Walk Down animation.
40-
DrawAsepriteTag(walkdown, 200, 100, WHITE);
47+
// Draw the 0th frame from the George sprite.
48+
DrawAseprite(george, 0, 100, 100, WHITE);
4149

50+
// Draw the Walk Down animation.
51+
DrawAsepriteTag(walkdown, 200, 100, WHITE);
52+
}
4253
EndDrawing();
4354
}
4455

45-
// Clean up the backpacker aseprite.
46-
UnloadAseprite(backpacker);
56+
// Clean up the George aseprite.
57+
UnloadAseprite(george);
4758

4859
CloseWindow();
4960
return 0;
5061
}
5162
```
5263

64+
See the [examples](examples directory) for more demonstrations of how to use *raylib-aseprite*.
65+
5366
### API
5467

5568
``` c
@@ -62,15 +75,15 @@ void TraceAseprite(Aseprite aseprite); // Display a
6275
Texture GetAsepriteTexture(Aseprite aseprite); // Retrieve the raylib texture associated with the aseprite
6376
int GetAsepriteWidth(Aseprite aseprite); // Get the width of the sprite
6477
int GetAsepriteHeight(Aseprite aseprite); // Get the height of the sprite
65-
int GetAspriteTagCount(Aseprite aseprite); // Get the total amount of available tags
78+
int GetAsepriteTagCount(Aseprite aseprite); // Get the total amount of available tags
6679
void DrawAseprite(Aseprite aseprite, int frame, int posX, int posY, Color tint);
6780
void DrawAsepriteV(Aseprite aseprite, int frame, Vector2 position, Color tint);
6881
void DrawAsepriteEx(Aseprite aseprite, int frame, Vector2 position, float rotation, float scale, Color tint);
6982
void DrawAsepritePro(Aseprite aseprite, int frame, Rectangle dest, Vector2 origin, float rotation, Color tint);
7083

7184
// Aseprite Tag functions
72-
AsepriteTag LoadAsepriteTag(Aseprite aseprite, const char* name); // Load a Aseprite tag animation sequence
73-
AsepriteTag LoadAsepriteTagFromIndex(Aseprite aseprite, int index); // Load a Aseprite tag animation sequence from its index
85+
AsepriteTag LoadAsepriteTag(Aseprite aseprite, const char* name); // Load an Aseprite tag animation sequence
86+
AsepriteTag LoadAsepriteTagFromIndex(Aseprite aseprite, int index); // Load an Aseprite tag animation sequence from its index
7487
bool IsAsepriteTagReady(AsepriteTag tag); // Check if the given Aseprite tag was loaded successfully
7588
void UpdateAsepriteTag(AsepriteTag* tag); // Update the tag animation frame
7689
AsepriteTag GenAsepriteTagDefault(); // Generate an empty Tag with sane defaults
@@ -98,4 +111,4 @@ This uses [cute_asesprite.h](https://github.com/RandyGaul/cute_headers/blob/mast
98111

99112
## License
100113

101-
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.
114+
*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.

examples/raylib-aseprite-example.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************************
22
*
3-
* [raylib-aseprite] example - Load a Aseprite file, and display the animated sprites.
3+
* [raylib-aseprite] example - Load a Aseprite file, and display the animated sprite.
44
*
55
* This example has been created using raylib 3.5 (www.raylib.com)
66
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
@@ -46,8 +46,8 @@ int main() {
4646
// Start the player facing down.
4747
int direction = 2;
4848

49-
// Center the player on the screen, and scale them.
50-
const float scale = 3;
49+
// Center the scaled player on the screen.
50+
const float scale = 4;
5151
Vector2 playerPosition = {
5252
GetScreenWidth() / 2 - GetAsepriteWidth(george) / 2 * scale,
5353
GetScreenHeight() / 2 - GetAsepriteHeight(george) / 2 * scale

examples/raylib-aseprite-example.png

419 Bytes
Loading

examples/raylib-aseprite-numbers.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************************
22
*
3-
* [raylib-aseprite] example - Load a Aseprite file, and display the animated sprites.
3+
* [raylib-aseprite] numbers - Load the numbers Aseprite file, and display the different animation directions.
44
*
55
* This example has been created using raylib 3.5 (www.raylib.com)
66
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
@@ -19,6 +19,7 @@
1919
int main() {
2020
// Initialization
2121
//--------------------------------------------------------------------------------------
22+
2223
const int screenWidth = 800;
2324
const int screenHeight = 450;
2425
const int textTop = 140;
@@ -28,6 +29,7 @@ int main() {
2829
// Load the Aseprite file.
2930
Aseprite numbers = LoadAseprite("resources/numbers.aseprite");
3031

32+
// Load the tag animations from the numbers aseprite.
3133
AsepriteTag forwards = LoadAsepriteTag(numbers, "Forwards");
3234
AsepriteTag backwards = LoadAsepriteTag(numbers, "Backwards");
3335
AsepriteTag pingpong = LoadAsepriteTag(numbers, "Ping-Pong");
@@ -47,6 +49,7 @@ int main() {
4749

4850
// Draw
4951
//----------------------------------------------------------------------------------
52+
5053
BeginDrawing();
5154
{
5255
ClearBackground(RAYWHITE);

examples/raylib-aseprite-numbers.png

13.2 KB
Loading

include/raylib-aseprite.h

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ void TraceAseprite(Aseprite aseprite); // Display a
7777
Texture GetAsepriteTexture(Aseprite aseprite); // Retrieve the raylib texture associated with the aseprite
7878
int GetAsepriteWidth(Aseprite aseprite); // Get the width of the sprite
7979
int GetAsepriteHeight(Aseprite aseprite); // Get the height of the sprite
80-
int GetAspriteTagCount(Aseprite aseprite); // Get the total amount of available tags
80+
int GetAsepriteTagCount(Aseprite aseprite); // Get the total amount of available tags
8181
void DrawAseprite(Aseprite aseprite, int frame, int posX, int posY, Color tint);
8282
void DrawAsepriteV(Aseprite aseprite, int frame, Vector2 position, Color tint);
8383
void DrawAsepriteEx(Aseprite aseprite, int frame, Vector2 position, float rotation, float scale, Color tint);
8484
void DrawAsepritePro(Aseprite aseprite, int frame, Rectangle dest, Vector2 origin, float rotation, Color tint);
8585

8686
// Aseprite Tag functions
87-
AsepriteTag LoadAsepriteTag(Aseprite aseprite, const char* name); // Load a Aseprite tag animation sequence
88-
AsepriteTag LoadAsepriteTagFromIndex(Aseprite aseprite, int index); // Load a Aseprite tag animation sequence from its index
87+
AsepriteTag LoadAsepriteTag(Aseprite aseprite, const char* name); // Load an Aseprite tag animation sequence
88+
AsepriteTag LoadAsepriteTagFromIndex(Aseprite aseprite, int index); // Load an Aseprite tag animation sequence from its index
8989
bool IsAsepriteTagReady(AsepriteTag tag); // Check if the given Aseprite tag was loaded successfully
9090
void UpdateAsepriteTag(AsepriteTag* tag); // Update the tag animation frame
9191
AsepriteTag GenAsepriteTagDefault(); // Generate an empty Tag with sane defaults
@@ -161,6 +161,9 @@ extern "C" {
161161
/**
162162
* Load an .aseprite file through its memory data.
163163
*
164+
* @param fileData The loaded file data for the .aseprite file.
165+
* @param size The size of file in bytes.
166+
*
164167
* @see UnloadAseprite()
165168
* @see LoadAseprite()
166169
*/
@@ -225,8 +228,12 @@ Aseprite LoadAsepriteFromMemory(unsigned char* fileData, unsigned int size) {
225228
/**
226229
* Load an .aseprite file.
227230
*
231+
* @param fileName The path to the file to load.
232+
*
233+
* @return The loaded Aseprite object, or an empty one on failure.
234+
*
228235
* @see UnloadAseprite()
229-
* @see LoadAsepriteFromMemory()
236+
* @see IsAsepriteReady()
230237
*/
231238
Aseprite LoadAseprite(const char* fileName) {
232239
unsigned int bytesRead;
@@ -243,12 +250,23 @@ Aseprite LoadAseprite(const char* fileName) {
243250
return ase;
244251
}
245252

253+
/**
254+
* Determine whether or not the given Aseprite object was loaded successfully.
255+
*
256+
* @param aseprite The loaded Aseprite object.
257+
*
258+
* @return True if the Aseprite was loaded successfully, false otherwise.
259+
*/
246260
bool IsAsepriteReady(Aseprite aseprite) {
247261
return aseprite.ase != 0;
248262
}
249263

250264
/**
251265
* Get the loaded raylib texture for the Aseprite.
266+
*
267+
* @param aseprite The loaded Aseprite object to retrieve the texture for.
268+
*
269+
* @return The internal texture associated with the Aseprite, or an empty Texture on failure.
252270
*/
253271
inline Texture GetAsepriteTexture(Aseprite aseprite) {
254272
if (aseprite.ase == 0) {
@@ -267,6 +285,10 @@ inline Texture GetAsepriteTexture(Aseprite aseprite) {
267285

268286
/**
269287
* Get the width of the aseprite sprite.
288+
*
289+
* @param aseprite The loaded Aseprite object to retrieve the width for.
290+
*
291+
* @return The width of the sprite, or 0 on failure.
270292
*/
271293
int GetAsepriteWidth(Aseprite aseprite) {
272294
if (aseprite.ase == 0) {
@@ -278,6 +300,10 @@ int GetAsepriteWidth(Aseprite aseprite) {
278300

279301
/**
280302
* Get the height of the aseprite sprite.
303+
*
304+
* @param aseprite The loaded Aseprite object to retrieve the height for.
305+
*
306+
* @return The height of the sprite, or 0 on failure.
281307
*/
282308
int GetAsepriteHeight(Aseprite aseprite) {
283309
if (aseprite.ase == 0) {
@@ -289,8 +315,12 @@ int GetAsepriteHeight(Aseprite aseprite) {
289315

290316
/**
291317
* Get the amount of tags defined in the aseprite sprite.
318+
*
319+
* @param aseprite The loaded Aseprite object to retrieve the amount of tags for.
320+
*
321+
* @return The number of tags that are defined within the aseprite, or 0 on failure.
292322
*/
293-
int GetAspriteTagCount(Aseprite aseprite) {
323+
int GetAsepriteTagCount(Aseprite aseprite) {
294324
if (aseprite.ase == 0) {
295325
TraceLog(LOG_WARNING, "ASEPRITE: Cannot get tag count non-existant aseprite");
296326
return 0;
@@ -299,7 +329,9 @@ int GetAspriteTagCount(Aseprite aseprite) {
299329
}
300330

301331
/**
302-
* Unloads the given Aseprite.
332+
* Unloads the given Aseprite. This will also unload the internal Texture.
333+
*
334+
* @param aseprite The loaded Aseprite object of which to unload.
303335
*
304336
* @see LoadAseprite()
305337
*/
@@ -510,6 +542,14 @@ AsepriteTag GenAsepriteTagDefault() {
510542

511543
/**
512544
* Load an Aseprite tag from the given index.
545+
*
546+
* @param aseprite The loaded Aseprite object from which to load the tag.
547+
* @param index The tag index within the Aseprite object.
548+
*
549+
* @return The Aseprite tag information, or an empty tag on failure.
550+
*
551+
* @see LoadAsepriteTag()
552+
* @see IsAsepriteTagReady()
513553
*/
514554
AsepriteTag LoadAsepriteTagFromIndex(Aseprite aseprite, int index) {
515555
AsepriteTag tag = GenAsepriteTagDefault();
@@ -542,6 +582,14 @@ AsepriteTag LoadAsepriteTagFromIndex(Aseprite aseprite, int index) {
542582

543583
/**
544584
* Load an Aseprite tag from the given name.
585+
*
586+
* @param aseprite The Aseprite object to load the tag from.
587+
* @param name The name of the tag to be loaded.
588+
*
589+
* @return The loaded Aseprite tag, or an empty tag on failure.
590+
*
591+
* @see IsAsepriteTagReady()
592+
* @see UpdateAsepriteTag()
545593
*/
546594
AsepriteTag LoadAsepriteTag(Aseprite aseprite, const char* name) {
547595
AsepriteTag tag = GenAsepriteTagDefault();
@@ -564,6 +612,10 @@ AsepriteTag LoadAsepriteTag(Aseprite aseprite, const char* name) {
564612

565613
/**
566614
* Determine whether or not the Aseprite tag was loaded successfully.
615+
*
616+
* @param tag The tag of which to check if it was loaded.
617+
*
618+
* @return True if the tag was loaded, false otherwise.
567619
*/
568620
bool IsAsepriteTagReady(AsepriteTag tag) {
569621
return tag.tag != 0;

test/raylib-aseprite-test.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ int main(int argc, char *argv[]) {
2828
// IsAsepriteReady()
2929
assert(IsAsepriteReady(aseprite));
3030

31+
// GetAsepriteWidth()
32+
assert(GetAsepriteWidth(aseprite) > 5);
33+
34+
// GetAsepriteHeight()
35+
assert(GetAsepriteHeight(aseprite) > 10);
36+
37+
// GetAsepriteTagCount()
38+
assert(GetAsepriteTagCount(aseprite) > 2);
39+
3140
// TraceAseprite()
3241
TraceAseprite(aseprite);
3342

@@ -43,8 +52,8 @@ int main(int argc, char *argv[]) {
4352
// IsAsepriteTagReady()
4453
assert(IsAsepriteTagReady(tag));
4554

46-
// GetAspriteTagCount()
47-
assert(GetAspriteTagCount(aseprite) > 2);
55+
// GetAsepriteTagCount()
56+
assert(GetAsepriteTagCount(aseprite) > 2);
4857

4958
// LoadAsepriteTagFromIndex()
5059
{

0 commit comments

Comments
 (0)