Skip to content

Commit 68e9a6b

Browse files
committed
Update struct definitions
1 parent aad22fe commit 68e9a6b

File tree

2 files changed

+49
-48
lines changed

2 files changed

+49
-48
lines changed

include/raylib-aseprite.h

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,13 @@
3333
#define INCLUDE_RAYLIB_ASEPRITE_H_
3434

3535
#include "raylib.h" // NOLINT
36-
#include "./cute_aseprite.h" // NOLINT
3736

3837
#ifdef __cplusplus
3938
extern "C" {
4039
#endif
4140

42-
/**
43-
* The loaded Aseprite data.
44-
*
45-
* @see LoadAseprite()
46-
* @see UnloadAseprite()
47-
*/
48-
typedef struct Aseprite {
49-
ase_t* ase; // Pointer to the cute_aseprite data.
50-
} Aseprite;
51-
52-
/**
53-
* Tag information from Aseprite.
54-
*
55-
* @see LoadAsepriteTag()
56-
* @see LoadAsepriteTagFromIndex()
57-
*/
58-
typedef struct AsepriteTag {
59-
char* name; // The name of the tag.
60-
int currentFrame; // The frame that the tag is currently on
61-
float timer; // The countdown timer in seconds
62-
int direction; // Whether we are moving forwards, or backwards through the frames
63-
float speed; // The animation speed factor (1 is normal speed, 2 is double speed)
64-
Color color; // The color provided for the tag
65-
bool loop; // Whether to continue to play the animation when the animation finishes
66-
bool paused; // Set to true to not progression of the animation
67-
Aseprite aseprite; // The loaded Aseprite file
68-
ase_tag_t* tag; // The active tag to act upon
69-
} AsepriteTag;
41+
typedef struct Aseprite Aseprite; // A loaded Aseprite file
42+
typedef struct AsepriteTag AsepriteTag; // A tag sprite animation within an Aseprite file
7043

7144
// Aseprite functions
7245
Aseprite LoadAseprite(const char* fileName); // Load an .aseprite file
@@ -108,6 +81,10 @@ void DrawAsepriteTagPro(AsepriteTag tag, Rectangle dest, Vector2 origin, float r
10881
#define CUTE_ASEPRITE_IMPLEMENTATION
10982
#endif
11083

84+
#ifdef __cplusplus
85+
extern "C" {
86+
#endif
87+
11188
// Have cute_aseprite report warnings through raylib.
11289
#define CUTE_ASEPRITE_WARNING(msg) TraceLog(LOG_WARNING, "ASEPRITE: %s (cute_headers.h:%i)", msg, __LINE__)
11390

@@ -154,9 +131,34 @@ void raylib_aseprite_fclose(CUTE_ASEPRITE_FILE* fp) {
154131

155132
#include "cute_aseprite.h" // NOLINT
156133

157-
#ifdef __cplusplus
158-
extern "C" {
159-
#endif
134+
/**
135+
* The loaded Aseprite data.
136+
*
137+
* @see LoadAseprite()
138+
* @see UnloadAseprite()
139+
*/
140+
struct Aseprite {
141+
ase_t* ase; // Pointer to the cute_aseprite data.
142+
};
143+
144+
/**
145+
* Tag information from Aseprite.
146+
*
147+
* @see LoadAsepriteTag()
148+
* @see LoadAsepriteTagFromIndex()
149+
*/
150+
struct AsepriteTag {
151+
char* name; // The name of the tag.
152+
int currentFrame; // The frame that the tag is currently on
153+
float timer; // The countdown timer in seconds
154+
int direction; // Whether we are moving forwards, or backwards through the frames
155+
float speed; // The animation speed factor (1 is normal speed, 2 is double speed)
156+
Color color; // The color provided for the tag
157+
bool loop; // Whether to continue to play the animation when the animation finishes
158+
bool paused; // Set to true to not progression of the animation
159+
Aseprite aseprite; // The loaded Aseprite file
160+
ase_tag_t* tag; // The active tag to act upon
161+
};
160162

161163
/**
162164
* Load an .aseprite file through its memory data.
@@ -468,24 +470,22 @@ void UpdateAsepriteTag(AsepriteTag* tag) {
468470
// Advance the frame and see if it's time to reset the position.
469471
tag->currentFrame += tag->direction;
470472
switch (aseTag->loop_animation_direction) {
471-
case ASE_ANIMATION_DIRECTION_BACKWORDS:
472-
if (tag->currentFrame < aseTag->from_frame) {
473+
case ASE_ANIMATION_DIRECTION_FORWARDS:
474+
if (tag->currentFrame > aseTag->to_frame) {
473475
if (tag->loop) {
474-
tag->currentFrame = aseTag->to_frame;
475-
}
476-
else {
477476
tag->currentFrame = aseTag->from_frame;
477+
} else {
478+
tag->currentFrame = aseTag->to_frame;
478479
tag->paused = true;
479480
}
480481
}
481482
break;
482-
case ASE_ANIMATION_DIRECTION_FORWARDS:
483-
if (tag->currentFrame > aseTag->to_frame) {
483+
case ASE_ANIMATION_DIRECTION_BACKWORDS:
484+
if (tag->currentFrame < aseTag->from_frame) {
484485
if (tag->loop) {
485-
tag->currentFrame = aseTag->from_frame;
486-
}
487-
else {
488486
tag->currentFrame = aseTag->to_frame;
487+
} else {
488+
tag->currentFrame = aseTag->from_frame;
489489
tag->paused = true;
490490
}
491491
}
@@ -496,20 +496,17 @@ void UpdateAsepriteTag(AsepriteTag* tag) {
496496
tag->direction = -1;
497497
if (tag->loop) {
498498
tag->currentFrame = aseTag->to_frame - 1;
499-
}
500-
else {
499+
} else {
501500
tag->currentFrame = aseTag->to_frame;
502501
tag->paused = true;
503502
}
504503
}
505-
}
506-
else {
504+
} else {
507505
if (tag->currentFrame < aseTag->from_frame) {
508506
tag->direction = 1;
509507
if (tag->loop) {
510508
tag->currentFrame = aseTag->from_frame + 1;
511-
}
512-
else {
509+
} else {
513510
tag->currentFrame = aseTag->from_frame;
514511
tag->paused = true;
515512
}

test/raylib-aseprite-test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ int main(int argc, char *argv[]) {
8787
DrawAsepriteTagEx(tag, (Vector2){10, 30}, 20, 3, WHITE);
8888
// DrawAsepriteTagPro()
8989
DrawAsepriteTagPro(tag, (Rectangle){30, 30, 20, 20}, (Vector2){0, 0}, 0.5f, WHITE);
90+
91+
// UpdateAsepriteTag()
92+
UpdateAsepriteTag(&tag);
93+
UpdateAsepriteTag(NULL);
9094
}
9195
EndDrawing();
9296

0 commit comments

Comments
 (0)