ase

Aseprite file format reader/writer


Keywords
ase, aseprite, format, gamedev, pixelart, haxe
License
MIT
Install
haxelib install ase 1.0.0

Documentation

MIT License Haxelib Version

ASE

.ase/.aseprite file format reader/writer written in Haxe with no external dependencies.

Implemented following the official Aseprite File Format (.ase/.aseprite) Specifications

Note that this library only provides reading and writing of the Aseprite file format. If you need rendering you will have to implement it yourself or use one of the existing rendering libraries:

Getting Started

Prerequisites

  • Haxe compiler
  • Haxelib

Installation

haxelib install ase

Usage

Parsing files

import sys.io.File;
import ase.Ase;

var data:Bytes = File.getBytes("path/to/file.aseprite");
var ase:Ase = Ase.fromBytes(data);

Now you can access some Aseprite file properties:

var spriteWidth:Int = ase.width;
var spriteHeight:Int = ase.height;
var spriteColorDepth:ColorDepth = ase.colorDepth;

Palette:

for(index in ase.palette.firstIndex...ase.palette.lastIndex+1) {
    var entry:PaletteEntry = ase.palette.getEntry(index);

    var r:Int = entry.r;
    var g:Int = entry.g;
    var b:Int = entry.b;
    var a:Int = entry.a;

    var rgbaColor = ase.palette.getRGBA(index);
    var argbColor = ase.palette.getARGB(index);
}

Layers:

for(layer in ase.layers) {
    var layerName:String = layer.name;
    var layerEditable:Bool = layer.editable;
    var layerVisible = layer.visible;
}

Frames:

for(frame in ase.frames) {
    var frameDuration = frame.duration;
}

Cels:

var layerIndex:Int = 0;

var celWidth:Int = frame.cel(layerIndex).width;
var celHeight:Int = frame.cel(layerIndex).height;
var celPixelData:Bytes = frame.cel(layerIndex).pixelData;

Create files

var spriteWidth:Int = 320;
var spriteHeight:Int = 320;
var colorDepth:ColorDepth = INDEXED;
var initialPalette:Array<Int> = [
    0x639bffff,
    0x5fcde4ff,
    0xcbdbfcff,
    0xffffffff,
    0x9badb7ff,
    0x847e87ff
];

var ase = new Ase.create(spriteWidth, spriteHeight, colorDepth);

Newly created file always comes with one blank frame. To add some content add at least one layer first:

ase.addLayer('Background');

Now to add some pixels to the sprite create a Cel on the first frame and the newly created layer:

var layerIndex:Int = 0;
var celWidth:Int = 200;
var celHeight:Int = 200;
var celXPosition:Int = 60;
var celYPosition:Int = 60;

var cel = ase.frames[0].createCel(
    layerIndex,
    celWidth,
    celHeight,
    celXPosition,
    celYPosition
);

There are a couple of methods to manipulate pixels of a cel:

cel.fillIndex(0); // Fill the cel with color #0 from the palette
cel.fillColor(0xff00ff00); // Fill the cel with ARGB color (for 32bpp mode)
cel.setPixel(20, 20, 0xff0033aa); // Set ARGB color at x and y
cel.setPixel(20, 20, 4); // Set color index at x and y
cel.setPixelData(bytes, 300, 300); // Set bytes of the pixel data (the size must me equal to width x height x bpp)

At any time you can get the file representation as bytes and, for example, store them to a file:

var bytes = ase.getBytes();
File.saveBytes('my_aseprite_file.aseprite', bytes);

License

This project is licensed under the MIT License - see the LICENSE.md file for details