Git Product home page Git Product logo

ase's Introduction

MIT License Haxelib Version

ASE

A .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 => entry in ase.palette.entries) {
    trace('Red: ${entry.red}, Green: ${entry.green}, Blue: ${entry.blue}, Alpha: ${entry.alpha}');

    // Alternatively, get the 32-bit integer RGBA or ARGB value
    var rgbaColor:Int = ase.palette.getRGBA(index);
    var argbColor:Int = ase.palette.getARGB(index);
    trace('RGBA: ${StringTools.hex(rgbaColor, 8)}, ARGB: ${StringTools.hex(argbColor, 8)}');
}

Layers:

for(layer in ase.layers) {
    var layerName:String = layer.name;
    var layerEditable:Bool = layer.editable;
    var layerVisible:Bool = 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;

Creating 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 = Ase.create(spriteWidth, spriteHeight, colorDepth);

A 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 be 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);

Contributors

See https://github.com/miriti/ase/graphs/contributors.

License

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

ase's People

Contributors

austineast avatar deepnight avatar ilemni avatar miriti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ase's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.