o
odinpkg.dev
packages / library / raylib-aseprite-odin

raylib-aseprite-odin

5cb7f44library

A lightweight Odin library for loading, animating, and drawing Aseprite sprites with raylib.

No license · updated 1 month ago

raylib-aseprite-odin

A fully native Odin package to load Aseprite files (.aseprite / .ase) and use them directly with vendor:raylib (Odin builtin binding).

This project is an Odin port of the raylib-aseprite API, without binding to the original C implementation.

Features

  • Load Aseprite sprites from file or memory
  • Build a texture atlas for frame-by-frame rendering
  • Handle Aseprite tags (forwards, backwards, ping-pong)
  • Handle Aseprite slices
  • Rendering helpers equivalent to the C library (DrawAseprite*, DrawAsepriteTag*)
  • Unit tests + runnable examples

Installation

Clone this repository, then import the package either with a relative import or an Odin collection.

Simple option (relative import)

import ase "../path/to/raylib-aseprite-odin"

Recommended option (collection)

odin run . -collection:raylib_aseprite=/path/to/raylib-aseprite-odin

Then in your code:

import ase "raylib_aseprite"

Quick Start

package main

import ase "../.."
import rl "vendor:raylib"

main :: proc() {
	rl.InitWindow(800, 450, "Aseprite + raylib + Odin")
	defer rl.CloseWindow()
	rl.SetTargetFPS(60)

	sprite := ase.LoadAseprite("examples/resources/george.aseprite")
	defer ase.UnloadAseprite(sprite)

	anim := ase.LoadAsepriteTag(sprite, "Walk-Down")

	for !rl.WindowShouldClose() {
		ase.UpdateAsepriteTag(&anim)

		rl.BeginDrawing()
		rl.ClearBackground(rl.RAYWHITE)
		ase.DrawAsepriteTagEx(anim, rl.Vector2{200, 120}, 0, 4, rl.WHITE)
		rl.EndDrawing()
	}
}

API

Detailed method-by-method documentation: DOCUMENTATION.md

Aseprite

  • LoadAseprite
  • LoadAsepriteFromMemory
  • IsAsepriteValid
  • UnloadAseprite
  • TraceAseprite
  • GetAsepriteTexture
  • GetAsepriteWidth
  • GetAsepriteHeight
  • DrawAseprite, DrawAsepriteFlipped, DrawAsepriteV, DrawAsepriteVFlipped
  • DrawAsepriteEx, DrawAsepriteExFlipped, DrawAsepritePro, DrawAsepriteProFlipped

Tags

  • LoadAsepriteTag
  • LoadAsepriteTagFromIndex
  • GetAsepriteTagCount
  • IsAsepriteTagValid
  • UpdateAsepriteTag
  • SetAsepriteTagFrame
  • GetAsepriteTagFrame
  • DrawAsepriteTag*

Slices

  • LoadAsepriteSlice
  • LoadAsepriteSliceFromIndex
  • GetAsepriteSliceCount
  • IsAsepriteSliceValid
  • GenAsepriteSliceDefault

Examples

Two examples are included:

  • examples/basic/main.odin
  • examples/numbers/main.odin

Run:

odin run examples/basic
odin run examples/numbers

Tests

odin test .

The main test file is raylib_aseprite_test.odin.

Project Structure

Notes

  • The parser supports the main chunks used by the original library (layers, cels, tags, palette, slices).
  • Animation playback uses rl.GetFrameTime() in UpdateAsepriteTag.
  • The package requires an initialized raylib window before loading (InitWindow).
  • Important: always register defer rl.CloseWindow() in main.
  • Important: register defer rl.CloseWindow() before any defer ase.UnloadAseprite(...). Odin executes defer in reverse order, so this guarantees UnloadAseprite runs while the raylib context is still valid.

Correct defer order:

// Wrong: can crash on exit (CloseWindow runs before UnloadAseprite)
sprite := ase.LoadAseprite("assets/player.aseprite")
defer ase.UnloadAseprite(sprite)
defer rl.CloseWindow()

// Correct: UnloadAseprite runs first, then CloseWindow
defer rl.CloseWindow()
defer ase.UnloadAseprite(sprite)

Credits

License

This project is licensed under the same zlib/libpng license used by the original raylib-aseprite project.


Built with curiosity, Python and a lot of AI.