Git Product home page Git Product logo

heaps-aseprite's Introduction

heaps-aseprite

Load and render sprites and animations in Aseprite format. Based on the ase and openfl-aseprite libraries. Sample Aseprite files all borrowed from openfl-aseprite.

Features

  • Hooks into the Heaps Engine's resource management to automatically handle any .aseprite or .ase file
  • Optimizes runtime performance by parsing Aseprite files during compilation (generating .png and .asedata files)
  • Supports all Color Modes, Animation Tags, Layers, and Slices (including 9-Slices!)
  • Includes the AseAnim Class to easily render Animations (based on the Heaps Engine's Anim Class)
  • Supports Live Resource Updating
  • Gets Type-safe references to an Aseprite file's Tags and Slices (thanks @deepnight!)

Getting Started

heaps-aseprite requires Haxe 4 and the Heaps Engine to run.

Install the library from haxelib:

haxelib install heaps-aseprite

Alternatively the dev version of the library can be installed from github:

haxelib git heaps-aseprite https://github.com/AustinEast/heaps-aseprite.git

Install heaps-aseprite's dependency, ase.

haxelib install ase

Then include the library in your project's .hxml:

-lib heaps-aseprite

Example

// Get the whole sprite as a Tile
var spr1 = new Bitmap(Res.single_frame_sprite.toAseprite().toTile(), s2d);

// Alternatively get the sprite directly as an Image
var image = new Bitmap(Res.single_frame_sprite.toImage().toTile(), s2d);

// Get an animation from the sprite's tag
var spr2 = new AseAnim(Res.animated_sprite.toAseprite().getTag('walk'), s2d);
spr2.loop = true;

// Override the direction of a tagged animation
var spr3 = new AseAnim(Res.animated_sprite.toAseprite().getTag('walk', AnimationDirection.REVERSE), s2d);
spr3.loop = true;

// Get an animation based on tag and slice
var spr4 = new AseAnim(Res.animated_sprite.toAseprite().getTag('walk', -1, 'Head'), s2d);
spr4.loop = true;

// Get a single frame from a slice
var slice = new Bitmap(Res.slices.toAseprite().getSlice('Slice 1').tile, s2d);

// Get all frames from a slice
var slice2 = new AseAnim(Res.slices.toAseprite().getSlices('Slice 1'), s2d);
slice2.loop = true;

// Get a 9-Slice ScaleGrid from a slice
var nineSlice = Res.nine_slices.toAseprite().toScaleGrid('9-Slices', 0, s2d);

// Live Resource Updatng
var animation = new AseAnim(Res.animated_sprite.toAseprite().getTag('walk'), s2d);
animation.loop = true;
Res.animated_sprite.watch(() -> {
  // Make sure to call the default `watch()` callback!
  Res.animated_sprite.updateData();

  // Replay the animation to get the updated frames
  animation.play(Res.animated_sprite.toAseprite().getTag('walk'));
});

// Want type-safe Tags and Slices? Use the `Dictionary` class to get typed references from an Aseprite resource
var typeSafeTags = Dictionary.getTags(Res.animated_sprite);
new AseAnim(Res.animated_sprite.toAseprite().getTag(typeSafeTags.walk), flow);

var typeSafeSlices = Dictionary.getSlices(Res.slices);
new Bitmap(Res.slices.toAseprite().getSlice(typeSafeSlices.Slice_1).tile, flow);

Roadmap

  • Document codebase (public fields and methods)

heaps-aseprite'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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

heaps-aseprite's Issues

Failure to read aseprite file

When running Aseprite 1.3 beta7, converting a layer to a Tilemap result in a failure to read the corresponding file when compiling.

Note converting the tilemap to a layer does not fix the issue.

Layer blend and opacity

It seems layer blend and opacity are not supported at the moment. Not using heaps-aseprite directly but noticed that by reading the code (and seeing opacity not taken into account in LDtk).

In my journey to implement aseprite support for Ceramic, I ported original aseprite's blend functions to Haxe, that you can find here: https://github.com/ceramic-engine/ceramic/blob/master/plugins/ase/runtime/src/ceramic/AsepriteBlendFuncs.hx

Sharing that as it could be interesting to use that in heaps-aseprite as well to improve support of layer blend/opacity (and make that work in LDtk as well?).

The actual parsing of ase data in Ceramic, also using the blend functions, can be found there: https://github.com/ceramic-engine/ceramic/blob/master/plugins/ase/runtime/src/ceramic/AsepriteParser.hx

heaps-aseprite no longer appears to work

Both in my own project, and when I clone this repo and compile the sample-js.hxml I get this runtime error:

Uncaught TypeError: can't access property 0, ase.get_firstFrame().chunkTypes.h[8217] is undefined

image

Or is this perhaps a fault with the haxe ase library?

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.