Load Aseprite files for animated sprites in raylib.

Overview

raylib-aseprite

Load Aseprite .aseprite files for animated sprites in raylib.

examples/raylib-aseprite-example.gif

Features

  • Load Aseprite files directly for use in raylib
  • Draw individual frames
  • Load and draw Aseprite 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 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. You will also have to link the raylib dependency.

Example

The below is a basic example, see the examples folder for more.

#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.
        UpdateAsperiteTag(&walkdown);

        BeginDrawing();
        {
            ClearBackground(RAYWHITE);

            // Draw the 0th 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 for more demonstrations of how to use raylib-aseprite.

API

// Aseprite functions
Aseprite LoadAseprite(const char* fileName);                        // Load an .aseprite file
Aseprite LoadAsepriteFromMemory(unsigned char* fileData, unsigned int size);  // Load an aseprite file from memory
bool IsAsepriteReady(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 IsAsepriteTagReady(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 IsAsepriteSliceReady(AsepriteSlice slice);                     // Return whether or not the given slice was found.
AsepriteSlice GenAsepriteSliceDefault();                            // Generate empty Aseprite slice data.

Development

To build the example locally, and run tests, use cmake.

git submodule update --init
mkdir build
cd build
cmake ..
make
cd examples
./raylib-aseprite-example

This uses cute_aseprite.h to handle loading the aseprite file. Thank you to Randy Gaul's 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 for further details.

You might also like...
My collection of raylib code examples - For learning the C language with 2D and 3D games.

Raylib-Examples My collection of raylib examples. ( https://www.raylib.com/index.html ) For Raylib Version of 4 april 2020 ( Notepad++ windows install

Minimalistic assertion library for raylib.

raylib-assert Minimalistic assertion library for raylib. Example #include "raylib.h" #include "raylib-assert.h" int main(void) { Assert(10 == 10)

A top-down shooter made for the raylib 5K gamejam.
A top-down shooter made for the raylib 5K gamejam.

ANTISPELL Description A top-down shooter where you have to use your enemies' attacks to spell your spells! Features Absorb letters getting close to en

runsc loads 32/64 bit shellcode (depending on how runsc is compiled) in a way that makes it easy to load in a debugger. This code is based on the code from https://github.com/Kdr0x/Kd_Shellcode_Loader by Gary "kd" Contreras.

runsc This code is based on the code from https://github.com/Kdr0x/Kd_Shellcode_Loader by Gary "kd" Contreras and contains additional functionality. T

A shebang-friendly script for "interpreting" single C99, C11, and C++ files, including rcfile support.

c99sh Basic Idea Control Files Shebang Tricks C++ C11 Credits Basic Idea A shebang-friendly script for "interpreting" single C99, C11, and C++ files,

A tool for use with clang to analyze #includes in C and C++ source files

Include What You Use For more in-depth documentation, see docs. Instructions for Users "Include what you use" means this: for every symbol (type, func

Libelf is a simple library to read ELF files

libelf Libelf is a simple library which provides functions to read ELF files. Headers #include stdint.h #include elf.h Structures typedef struct

ByteCopy , or BCP, intends to copy files accurately (down to the bytes) in a simple , safe and efficient manner.

ByteCopy v3.6 About ByteCopy , or BCP, intends to copy files accurately (down to the bytes) in a simple , safe and efficient manner. It's functionalit

Cobalt Strike BOF Files with Nim!
Cobalt Strike BOF Files with Nim!

BOF-Nim oh yeah baby I have an inkling it's possible, right now the problem seems to be getting the go function to be present in the Symbol table. No

Comments
  • C++ compilation error fix

    C++ compilation error fix

    "fixed error: designator order for field ‘Color::r’ does not match declaration order in ‘Color’" and "error: designator order for field ‘Image::mipmaps’ does not match declaration order in ‘Image’".

    opened by demon-i386 1
  • STATIC

    STATIC

    https://github.com/nothings/stb/blob/master/docs/stb_howto.txt

    ALLOW STATIC IMPLEMENTATION
    

    Have a #define which makes function declarations and function definitions static. This makes the implementation private to the source file that creates it. This allows people to use your library multiple times in their project without collision. (This is only necessary if your library has configuration macros or global state, or if your library has multiple versions that are not backwards compatible. I've run into both of those cases.)

    opened by RobLoach 0
Releases(v4.2.1)
Owner
Rob Loach
Rob Loach
A simple application that generates animated BTTV emotes from static images

emoteJAM WARNING! The application is in active development and can't do anything yet. A simple application that generates animated BTTV emotes from st

Tsoding 7 Apr 27, 2021
Utilities and common code for use with raylib

Utilities and shared components for use with raylib

Jeffery Myers 86 Dec 1, 2022
The Ultimate Raylib gaming library wrapper for Nim

NimraylibNow! - The Ultimate Raylib wrapper for Nim The most idiomatic and up-to-date wrapper for Raylib gaming C library. Use this library if you wan

Dmitry Matveyev 138 Dec 22, 2022
RayLib extern bindings for Haxe

raylib-haxe Haxe bindings for RayLib usage haxelib git raylib-haxe https://github.com/haxeui/raylib-haxe package; import RayLib.*; import RayLib.Cam

HaxeUI 24 Dec 3, 2022
Haxe bindings for raylib, a simple and easy-to-use library to learn videogame programming

Haxe bindings for raylib, a simple and easy-to-use library to learn videogame programming, Currently works only for windows but feel free the expand t

FSasquatch 36 Dec 16, 2022
SWIG bindings for raylib (to Lua, and hopefully other languages)

swigraylib SWIG binding for raylib This repo generates raylib bindings to other languages (eg. Lua), by providing a raylib.i SWIG interface file. SWIG

null 6 Oct 28, 2021
A pong clone written in C++ with Raylib

How To Play Objective: first player to reach 10 points is the winner! PLAYER 1: W: up S: down PLAYER 2: ARROW UP or I: up ARROW DOWN or S: down Requir

Victor Sarkisov 1 Nov 8, 2021
autogen bindings to Raylib 4.0 and convenience wrappers on top. Requires use of `unsafe`

Raylib-CsLo Raylib-CsLo LowLevel autogen bindings to Raylib 4.0 and convenience wrappers on top. Requires use of unsafe A focus on performance. No run

NotNot 69 Dec 18, 2022
Pong clone made in C++ with raylib

Raypong Pong clone made in C++ with raylib. Dependencies ...C++ and raylib lol Building To build, use these commands: mkdir build # Create a build dir

Mars 0 Feb 4, 2022
raylib Nuget package

raylib Nuget package This is a Nuget package for the popular raylib video game programming library. Resources used to create this package are as follo

Samuel Gomes 6 Dec 5, 2022