Skip to content

Commit 3fde891

Browse files
committed
v0.2.1
1 parent 0120f04 commit 3fde891

12 files changed

+276
-138
lines changed

CMakeLists.txt

Lines changed: 5 additions & 5 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.0
3+
VERSION 0.2.1
44
DESCRIPTION "raylib-aseprite"
55
HOMEPAGE_URL "https://github.com/robloach/raylib-aseprite"
66
LANGUAGES C)
@@ -9,15 +9,15 @@ project (raylib-aseprite
99
add_subdirectory(include)
1010

1111
# Examples
12-
option(RAYLIB_ASEPRITE_BUILD_EXAMPLE "Example" ON)
13-
if(RAYLIB_ASEPRITE_BUILD_EXAMPLE)
14-
add_subdirectory(example)
12+
option(RAYLIB_ASEPRITE_BUILD_EXAMPLES "Example" ON)
13+
if(RAYLIB_ASEPRITE_BUILD_EXAMPLES)
14+
add_subdirectory(examples)
1515
endif()
1616

1717
# Testing
1818
include(CTest)
1919
enable_testing()
20-
if(BUILD_TESTING AND RAYLIB_ASEPRITE_BUILD_EXAMPLE)
20+
if(BUILD_TESTING AND RAYLIB_ASEPRITE_BUILD_EXAMPLES)
2121
set(CTEST_CUSTOM_TESTS_IGNORE
2222
pkg-config--static
2323
)

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,26 @@ int main() {
5353
### Cheatsheet
5454

5555
``` c
56-
// Aseprite
56+
// Aseprite functions
5757
Aseprite LoadAseprite(const char* fileName); // Load an .aseprite file
5858
Aseprite LoadAsepriteFromMemory(unsigned char* fileData, unsigned int size); // Load an aseprite file from memory
59-
bool IsAsepriteReady(Aseprite aseprite); // Check if the given Aseprite was loaded successfully.
59+
bool IsAsepriteReady(Aseprite aseprite); // Check if the given Aseprite was loaded successfully
6060
void UnloadAseprite(Aseprite aseprite); // Unloads the aseprite file
6161
void TraceAseprite(Aseprite aseprite); // Display all information associated with the aseprite
6262
Texture GetAsepriteTexture(Aseprite aseprite); // Retrieve the raylib texture associated with the aseprite
63-
int GetAsepriteWidth(Aseprite aseprite); // Get the width of the sprite.
64-
int GetAsepriteHeight(Aseprite aseprite); // Get the height of the sprite.
63+
int GetAsepriteWidth(Aseprite aseprite); // Get the width of the sprite
64+
int GetAsepriteHeight(Aseprite aseprite); // Get the height of the sprite
6565
int GetAspriteTagCount(Aseprite aseprite); // Get the total amount of available tags
6666
void DrawAseprite(Aseprite aseprite, int frame, int posX, int posY, Color tint);
6767
void DrawAsepriteV(Aseprite aseprite, int frame, Vector2 position, Color tint);
6868
void DrawAsepriteEx(Aseprite aseprite, int frame, Vector2 position, float rotation, float scale, Color tint);
6969
void DrawAsepritePro(Aseprite aseprite, int frame, Rectangle dest, Vector2 origin, float rotation, Color tint);
7070

71-
// AsepriteTag
71+
// Aseprite Tag functions
7272
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
74-
bool IsAsepriteTagReady(AsepriteTag tag); // Check if the given Aseprite tag was loaded successfully.
75-
void UpdateAsepriteTag(AsepriteTag* tag); // Update the tag animation frame if needed
73+
AsepriteTag LoadAsepriteTagFromIndex(Aseprite aseprite, int index); // Load a Aseprite tag animation sequence from its index
74+
bool IsAsepriteTagReady(AsepriteTag tag); // Check if the given Aseprite tag was loaded successfully
75+
void UpdateAsepriteTag(AsepriteTag* tag); // Update the tag animation frame
7676
AsepriteTag GenAsepriteTagDefault(); // Generate an empty Tag with sane defaults
7777
void DrawAsepriteTag(AsepriteTag tag, int posX, int posY, Color tint);
7878
void DrawAsepriteTagV(AsepriteTag tag, Vector2 position, Color tint);

example/raylib-aseprite-example.c

Lines changed: 0 additions & 118 deletions
This file was deleted.

example/resources/backpacker.aseprite

-2.78 KB
Binary file not shown.

example/CMakeLists.txt renamed to examples/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ target_link_libraries(raylib-aseprite-example PUBLIC
1313
raylib-aseprite
1414
)
1515

16+
# raylib-aseprite-numbers
17+
add_executable(raylib-aseprite-numbers raylib-aseprite-numbers.c)
18+
target_link_libraries(raylib-aseprite-numbers PUBLIC
19+
raylib
20+
raylib-aseprite
21+
)
22+
1623
# Copy the resources
1724
file(GLOB resources resources/*)
1825
set(test_resources)

examples/raylib-aseprite-example.c

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*******************************************************************************************
2+
*
3+
* [raylib-aseprite] example - Load a Aseprite file, and display the animated sprites.
4+
*
5+
* This example has been created using raylib 3.5 (www.raylib.com)
6+
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
7+
*
8+
* Example by Rob Loach (@RobLoach)
9+
*
10+
* Copyright (c) 2021 Rob Loach (@RobLoach)
11+
*
12+
********************************************************************************************/
13+
14+
#include "raylib.h"
15+
16+
#define RAYLIB_ASEPRITE_IMPLEMENTATION
17+
#include "raylib-aseprite.h"
18+
19+
int main() {
20+
// Initialization
21+
//--------------------------------------------------------------------------------------
22+
const int screenWidth = 800;
23+
const int screenHeight = 450;
24+
InitWindow(screenWidth, screenHeight, "[raylib-aseprite] example");
25+
SetTargetFPS(60);
26+
27+
// Load the Aseprite file.
28+
Aseprite george = LoadAseprite("resources/george.aseprite");
29+
30+
// Load the standing animations from the Aseprite tags.
31+
AsepriteTag standing[4] = {
32+
LoadAsepriteTag(george, "Stand-Up"),
33+
LoadAsepriteTag(george, "Stand-Right"),
34+
LoadAsepriteTag(george, "Stand-Down"),
35+
LoadAsepriteTag(george, "Stand-Left")
36+
};
37+
38+
// Load the moving animations from the Aseprite tags.
39+
AsepriteTag moving[4] = {
40+
LoadAsepriteTag(george, "Walk-Up"),
41+
LoadAsepriteTag(george, "Walk-Right"),
42+
LoadAsepriteTag(george, "Walk-Down"),
43+
LoadAsepriteTag(george, "Walk-Left")
44+
};
45+
46+
// Start the player facing down.
47+
int direction = 2;
48+
49+
// Center the player on the screen, and scale them.
50+
const float scale = 3;
51+
Vector2 playerPosition = {
52+
GetScreenWidth() / 2 - GetAsepriteWidth(george) / 2 * scale,
53+
GetScreenHeight() / 2 - GetAsepriteHeight(george) / 2 * scale
54+
};
55+
56+
// How fast the player should move around.
57+
const float speed = 2;
58+
59+
// Whether or not the player is actively moving.
60+
bool playerMoving;
61+
//--------------------------------------------------------------------------------------
62+
63+
while(!WindowShouldClose()) {
64+
65+
// Update
66+
//----------------------------------------------------------------------------------
67+
if (IsKeyDown(KEY_UP)) {
68+
direction = 0;
69+
playerMoving = true;
70+
}
71+
else if (IsKeyDown(KEY_RIGHT)) {
72+
direction = 1;
73+
playerMoving = true;
74+
}
75+
else if (IsKeyDown(KEY_DOWN)) {
76+
direction = 2;
77+
playerMoving = true;
78+
}
79+
else if (IsKeyDown(KEY_LEFT)) {
80+
direction = 3;
81+
playerMoving = true;
82+
}
83+
else {
84+
playerMoving = false;
85+
}
86+
87+
if (playerMoving) {
88+
// Update the active moving animation.
89+
UpdateAsepriteTag(&moving[direction]);
90+
91+
// Move the player.
92+
switch (direction) {
93+
case 0:
94+
playerPosition.y -= speed;
95+
break;
96+
case 1:
97+
playerPosition.x += speed;
98+
break;
99+
case 2:
100+
playerPosition.y += speed;
101+
break;
102+
case 3:
103+
playerPosition.x -= speed;
104+
break;
105+
}
106+
}
107+
//----------------------------------------------------------------------------------
108+
109+
// Draw
110+
//----------------------------------------------------------------------------------
111+
BeginDrawing();
112+
{
113+
ClearBackground(RAYWHITE);
114+
115+
// Draw either the moving, or standing animation.
116+
if (playerMoving) {
117+
DrawAsepriteTagEx(moving[direction], playerPosition, 0, scale, WHITE);
118+
}
119+
else {
120+
DrawAsepriteTagEx(standing[direction], playerPosition, 0, scale, WHITE);
121+
}
122+
}
123+
EndDrawing();
124+
//----------------------------------------------------------------------------------
125+
}
126+
127+
// De-Initialization
128+
//--------------------------------------------------------------------------------------
129+
130+
UnloadAseprite(george); // Unload the Aseprite data.
131+
132+
CloseWindow();
133+
//--------------------------------------------------------------------------------------
134+
135+
return 0;
136+
}

0 commit comments

Comments
 (0)