#sprite-sheet #animation #bevy #2d #assets #json-array

bevy_ss_anim

从 Adobe Animate 生成的精灵表生成的动画精灵

11 个版本

0.2.2 2023 年 9 月 22 日
0.2.1 2023 年 9 月 1 日
0.1.2 2023 年 9 月 1 日
0.1.1 2023 年 8 月 31 日
0.0.5 2023 年 8 月 31 日

#1611游戏开发

Download history 2/week @ 2024-03-09 56/week @ 2024-03-30 12/week @ 2024-04-06

67 每月下载次数

自定义许可

33KB
497

Bevy tracking crates.io docs.rs

Bevy 精灵表动画

这个包目前可以使用以下数据格式从 Adobe Animate 生成的精灵表中创建动画精灵:

  • Sparrow V1
  • Sparrow V2
  • Starling
  • Json
  • Json Array
  • Edge Animate

免责声明!

这个项目处于早期开发阶段,所以一些内容可能会发生变化。

如何使用这个包

这个示例使用 Sparrow,如果支持其他数据格式,您当然也可以像这样使用它们。

// bevy version: 0.11.2
use bevy::prelude::*;
use bevy_ss_anim;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, (jump, bevy_ss_anim::update_animations))
        .run();
}

fn setup(
    mut commands: Commands,
    mut texture_atlases: ResMut<Assets<TextureAtlas>>,
    asset_server: Res<AssetServer>,
) {
    // spawn camera since nothing would get rendered without it
    commands.spawn(Camera2dBundle::default());

    // in assets/images/ you would have the player.png and player.xml files
    // path to png and xml, texture atlases, asset server
    let bundle = bevy_ss_anim::AnimatedSpriteBundle::from_sparrow("images/player", &mut texture_atlases, &asset_server);

    if let Some(mut bundle) = bundle {
        // animation name, animation prefix in xml, fps, looped, offset
        bundle.animated_sprite.add_animation_by_prefix("idle", "Idle", 24, true, Vec2::default());
        bundle.animated_sprite.add_animation_by_prefix("jump", "Jump", 24, false, Vec2::new(-5f32, 25f32));

        bundle.sprite_sheet_bundle.transform.scale = Vec3::new(0.5, 0.5, 0.5);

        // animation name, forced, texture atlas sprite, transform
        bundle.animated_sprite.play_animation("idle", true, &mut bundle.sprite_sheet_bundle.sprite, &mut bundle.sprite_sheet_bundle.transform);

        commands.spawn(bundle);
    }
}

fn jump(
    input: Res<Input<KeyCode>>,
    mut query: Query<(&mut bevy_ss_anim::AnimatedSprite, &mut TextureAtlasSprite, &mut Transform)>,
) {
    for (mut animated_sprite, mut sprite, mut transform) in query.iter_mut() {
        if animated_sprite.animation_is_finished {
            animated_sprite.play_animation("idle", true, &mut sprite, &mut transform);
        }

        if input.just_pressed(KeyCode::Space) && animated_sprite.current_animation().name != "jump" {
            animated_sprite.play_animation("jump", true, &mut sprite, &mut transform);
        }
    }
}

依赖项

~38–53MB
~738K SLoC