Giter Site home page Giter Site logo

bevy-sprite-sheet-animation's Introduction

Bevy tracking crates.io docs.rs

Bevy Sprite Sheet Animation

This Crate Currently Can Create An Animated Sprite From A Sprite Sheet Generated In Adobe Animate Using The Data Formats:

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

Disclaimer!

This Is In Early Development So Stuff Is Subject To Change

How To Use This Crate

This Example Uses Sparrow, If Other Data Formats Are Supported You Can Of Course Also Use Them Similarly To This

// 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);
        }
    }
}

bevy-sprite-sheet-animation's People

Contributors

0x330a avatar lemz1 avatar

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.