Skip to content

Commit 3c79b91

Browse files
authored
Merge pull request #24 from RobLoach/flip
Add Flip methods
2 parents 77b98a9 + f6c68dd commit 3c79b91

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

examples/raylib-aseprite-example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int main() {
5656
DrawAseprite(george, 0, 100, 100, WHITE);
5757
DrawAseprite(george, 4, 100, 150, WHITE);
5858
DrawAseprite(george, 8, 100, 200, WHITE);
59-
DrawAseprite(george, 12, 100, 250, WHITE);
59+
DrawAsepriteFlipped(george, 12, 100, 250, false, true, WHITE);
6060

6161
// Draw the walking animation.
6262
DrawAsepriteTagEx(walking, position, 0, scale, WHITE);

include/raylib-aseprite.h

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ Texture GetAsepriteTexture(Aseprite aseprite); // Retrieve
8989
int GetAsepriteWidth(Aseprite aseprite); // Get the width of the sprite
9090
int GetAsepriteHeight(Aseprite aseprite); // Get the height of the sprite
9191
void DrawAseprite(Aseprite aseprite, int frame, int posX, int posY, Color tint);
92+
void DrawAsepriteFlipped(Aseprite aseprite, int frame, int posX, int posY, bool horizontalFlip, bool verticalFlip, Color tint);
9293
void DrawAsepriteV(Aseprite aseprite, int frame, Vector2 position, Color tint);
93-
void DrawAsepriteEx(Aseprite aseprite, int frame, Vector2 position, float rotation, float scale, Color tint);
94+
void DrawAsepriteVFlipped(Aseprite aseprite, int frame, Vector2 position, bool horizontalFlip, bool verticalFlip, Color tint);
95+
void DrawAsepriteExFlipped(Aseprite aseprite, int frame, Vector2 position, float rotation, float scale, bool horizontalFlip, bool verticalFlip, Color tint);
9496
void DrawAsepritePro(Aseprite aseprite, int frame, Rectangle dest, Vector2 origin, float rotation, Color tint);
97+
void DrawAsepriteProFlipped(Aseprite aseprite, int frame, Rectangle dest, Vector2 origin, float rotation, bool horizontalFlip, bool verticalFlip, Color tint);
9598

9699
// Aseprite Tag functions
97100
AsepriteTag LoadAsepriteTag(Aseprite aseprite, const char* name); // Load an Aseprite tag animation sequence
@@ -101,9 +104,13 @@ bool IsAsepriteTagReady(AsepriteTag tag); // Check if
101104
void UpdateAsepriteTag(AsepriteTag* tag); // Update the tag animation frame
102105
AsepriteTag GenAsepriteTagDefault(); // Generate an empty Tag with sane defaults
103106
void DrawAsepriteTag(AsepriteTag tag, int posX, int posY, Color tint);
107+
void DrawAsepriteTagFlipped(AsepriteTag tag, int posX, int posY, bool horizontalFlip, bool verticalFlip, Color tint);
104108
void DrawAsepriteTagV(AsepriteTag tag, Vector2 position, Color tint);
109+
void DrawAsepriteTagVFlipped(AsepriteTag tag, Vector2 position, bool horizontalFlip, bool verticalFlip, Color tint);
105110
void DrawAsepriteTagEx(AsepriteTag tag, Vector2 position, float rotation, float scale, Color tint);
111+
void DrawAsepriteTagExFlipped(AsepriteTag tag, Vector2 position, float rotation, float scale, bool horizontalFlip, bool verticalFlip, Color tint);
106112
void DrawAsepriteTagPro(AsepriteTag tag, Rectangle dest, Vector2 origin, float rotation, Color tint);
113+
void DrawAsepriteTagProFlipped(AsepriteTag tag, Rectangle dest, Vector2 origin, float rotation, bool horizontalFlip, bool verticalFlip, Color tint);
107114
void SetAsepriteTagFrame(AsepriteTag* tag, int frameNumber); // Sets which frame the tag is currently displaying.
108115
int GetAsepriteTagFrame(AsepriteTag tag);
109116

@@ -362,41 +369,57 @@ void UnloadAseprite(Aseprite aseprite) {
362369
}
363370

364371
void DrawAseprite(Aseprite aseprite, int frame, int posX, int posY, Color tint) {
372+
DrawAsepriteFlipped(aseprite, frame, posX, posY, false, false, tint);
373+
}
374+
375+
void DrawAsepriteFlipped(Aseprite aseprite, int frame, int posX, int posY, bool horizontalFlip, bool verticalFlip, Color tint) {
365376
Vector2 position = {(float)posX, (float)posY};
366-
DrawAsepriteV(aseprite, frame, position, tint);
377+
DrawAsepriteVFlipped(aseprite, frame, position, horizontalFlip, verticalFlip, tint);
367378
}
368379

369380
void DrawAsepriteV(Aseprite aseprite, int frame, Vector2 position, Color tint) {
381+
DrawAsepriteVFlipped(aseprite, frame, position, false, false, tint);
382+
}
383+
384+
void DrawAsepriteVFlipped(Aseprite aseprite, int frame, Vector2 position, bool horizontalFlip, bool verticalFlip, Color tint) {
370385
ase_t* ase = aseprite.ase;
371386
if (ase == 0 || frame < 0 || frame >= ase->frame_count) {
372387
return;
373388
}
374389

375-
Rectangle source = {(float)(frame * ase->w), 0, (float)ase->w, (float)ase->h};
390+
Rectangle source = {(float)(frame * ase->w), 0, horizontalFlip ? (float)-ase->w : ase->w, verticalFlip ? (float)-ase->h : (float)ase->h};
376391
Texture2D texture = GetAsepriteTexture(aseprite);
377392
DrawTextureRec(texture, source, position, tint);
378393
}
379394

380395
void DrawAsepriteEx(Aseprite aseprite, int frame, Vector2 position, float rotation, float scale, Color tint) {
396+
DrawAsepriteExFlipped(aseprite, frame, position, rotation, scale, false, false, tint);
397+
}
398+
399+
void DrawAsepriteExFlipped(Aseprite aseprite, int frame, Vector2 position, float rotation, float scale, bool horizontalFlip, bool verticalFlip, Color tint) {
381400
ase_t* ase = aseprite.ase;
382401
if (ase == 0 || frame < 0 || frame >= ase->frame_count) {
383402
return;
384403
}
385404

386-
Rectangle source = {(float)(frame * ase->w), 0, (float)ase->w, (float)ase->h};
405+
Rectangle source = {(float)(frame * ase->w), 0, horizontalFlip ? (float)-ase->w : ase->w, verticalFlip ? (float)-ase->h : (float)ase->h};
387406
Texture2D texture = GetAsepriteTexture(aseprite);
388407
Rectangle dest = {(float)position.x, (float)position.y, (float)ase->w * scale, (float)ase->h * scale};
389408
Vector2 origin = {0, 0};
390409
DrawTexturePro(texture, source, dest, origin, rotation, tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters
391410
}
392411

393412
void DrawAsepritePro(Aseprite aseprite, int frame, Rectangle dest, Vector2 origin, float rotation, Color tint) {
413+
DrawAsepriteProFlipped(aseprite, frame, dest, origin, rotation, false, false, tint);
414+
}
415+
416+
void DrawAsepriteProFlipped(Aseprite aseprite, int frame, Rectangle dest, Vector2 origin, float rotation, bool horizontalFlip, bool verticalFlip, Color tint) {
394417
ase_t* ase = aseprite.ase;
395418
if (ase == 0 || frame < 0 || frame >= ase->frame_count) {
396419
return;
397420
}
398421

399-
Rectangle source = {(float)(frame * ase->w), 0, (float)ase->w, (float)ase->h};
422+
Rectangle source = {(float)(frame * ase->w), 0, horizontalFlip ? (float)-ase->w : ase->w, verticalFlip ? (float)-ase->h : (float)ase->h};
400423
Texture2D texture = GetAsepriteTexture(aseprite);
401424
DrawTexturePro(texture, source, dest, origin, rotation, tint);
402425
}
@@ -544,18 +567,34 @@ void DrawAsepriteTag(AsepriteTag tag, int posX, int posY, Color tint) {
544567
DrawAseprite(tag.aseprite, tag.currentFrame, posX, posY, tint);
545568
}
546569

570+
void DrawAsepriteTagFlipped(AsepriteTag tag, int posX, int posY, bool horizontalFlip, bool verticalFlip, Color tint) {
571+
DrawAsepriteFlipped(tag.aseprite, tag.currentFrame, posX, posY, horizontalFlip, verticalFlip, tint);
572+
}
573+
547574
void DrawAsepriteTagV(AsepriteTag tag, Vector2 position, Color tint) {
548575
DrawAsepriteV(tag.aseprite, tag.currentFrame, position, tint);
549576
}
550577

578+
void DrawAsepriteTagVFlipped(AsepriteTag tag, Vector2 position, bool horizontalFlip, bool verticalFlip, Color tint) {
579+
DrawAsepriteVFlipped(tag.aseprite, tag.currentFrame, position, horizontalFlip, verticalFlip, tint);
580+
}
581+
551582
void DrawAsepriteTagEx(AsepriteTag tag, Vector2 position, float rotation, float scale, Color tint) {
552583
DrawAsepriteEx(tag.aseprite, tag.currentFrame, position, rotation, scale, tint);
553584
}
554585

586+
void DrawAsepriteTagExFlipped(AsepriteTag tag, Vector2 position, float rotation, float scale, bool horizontalFlip, bool verticalFlip, Color tint) {
587+
DrawAsepriteExFlipped(tag.aseprite, tag.currentFrame, position, rotation, scale, horizontalFlip, verticalFlip, tint);
588+
}
589+
555590
void DrawAsepriteTagPro(AsepriteTag tag, Rectangle dest, Vector2 origin, float rotation, Color tint) {
556591
DrawAsepritePro(tag.aseprite, tag.currentFrame, dest, origin, rotation, tint);
557592
}
558593

594+
void DrawAsepriteTagProFlipped(AsepriteTag tag, Rectangle dest, Vector2 origin, float rotation, bool horizontalFlip, bool verticalFlip, Color tint) {
595+
DrawAsepriteProFlipped(tag.aseprite, tag.currentFrame, dest, origin, rotation, horizontalFlip, verticalFlip, tint);
596+
}
597+
559598
/**
560599
* Generate an aseprite tag with sane defaults.
561600
*

0 commit comments

Comments
 (0)