Crate bevy_ase

source ·
Expand description

Utilities for loading Aseprite files into a Bevy application.

Provides Loader, an AssetLoader struct which directly reads .aseprite files without an intermediate import step. The loader adds Resources generated by the files’ data. Systems can invoke the loader’s methods to start loading files, or query the loading state.

Resources

This library creates several types of resources:

  • Image data, which contains the file’s images.
  • TextureAtlas data, which contains mapping information for each sprite in a spritesheet.
  • Animation data.
  • Slice data.
  • Tileset data (from files created in Aseprite v1.3 beta).

Configuration

This library exposes a plugin with default settings. This plugin initializes all of the above resources as Asset types, adds Loader and AseAssetLoader resources, and adds an importer system function to process loaded ase data. For a custom configuration, import the constituent parts and add them to AppBuilder directly. The Texture resource is required to be initialized. Other asset types are optional.

Examples

use bevy::prelude::*;
use bevy_ase::asset::AseAsset;
use bevy_ase::loader::{AseLoaderDefaultPlugin, Loader};
use std::path::Path;

// Initialize and run a bevy app with the default bevy_ase configuration.
fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(AseLoaderDefaultPlugin)
        .add_systems(Startup, load_sprites);
}

// Get an aseprite asset and send it to the loader.
pub fn load_sprites(asset_server: Res<AssetServer>, mut loader: ResMut<Loader>) {
    let h: Handle<AseAsset> = asset_server.load(Path::new("sprites/hello.aseprite"));
    loader.add(h.clone());
}

Optional Features

Benimator

When compiled with the “benimator” feature, this library includes a From implementation to convert Animation assets into benimator SpriteSheetAnimation assets.

Example

use bevy::prelude::*;
use bevy_ase;
#[cfg(feature = "benimator")]
use benimator;

// Creates a benimator animation asset whenever a bevy_ase animation asset is created.
#[cfg(feature = "benimator")]
pub fn convert_animation(
    mut event_reader: EventReader<AssetEvent<bevy_ase::asset::Animation>>,
    animations: Res<Assets<bevy_ase::asset::Animation>>,
    mut sprite_sheet_animations: ResMut<Assets<benimator::SpriteSheetAnimation>>,
) {
    for evt in event_reader.iter() {
        if let AssetEvent::Created { handle } = evt {
            // Unwrap: Responding to Asset Created event, so asset exists
            let anim = animations.get(handle).unwrap();
            let converted_animation = anim.into();
            sprite_sheet_animations.add(converted_animation);
        }
    }
}

Modules

  • Provides asset types for working with Aseprite data.
  • Provides functions to generate HandleIds for assets generated from aseprite files.
  • Provides systems and resources for loading Aseprite files.