From 694409cfbe7cefb5dd5708d9768902fec1676e79 Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Wed, 16 Jun 2021 22:07:03 +0200 Subject: [PATCH] docs(readme): Write a readme --- README.md | 81 ++++++++++++++++++++++++++++++++ docs/coin.gif | Bin 0 -> 18043 bytes examples/{demo.rs => readme.rs} | 32 ++++++------- src/lib.rs | 2 +- 4 files changed, 97 insertions(+), 18 deletions(-) create mode 100644 README.md create mode 100644 docs/coin.gif rename examples/{demo.rs => readme.rs} (50%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..4092724 --- /dev/null +++ b/README.md @@ -0,0 +1,81 @@ +# Heron + +[![License](https://img.shields.io/github/license/jcornaz/benimator)](https://github.com/jcornaz/benimator/blob/main/LICENSE) +[![Crates.io](https://img.shields.io/crates/v/benimator)](https://crates.io/crates/benimator) +[![Docs](https://docs.rs/benimator/badge.svg)](https://docs.rs/benimator) +[![Bevy tracking](https://img.shields.io/badge/Bevy%20tracking-released%20version-lightblue)](https://github.com/bevyengine/bevy/blob/main/docs/plugins_guidelines.md#main-branch-tracking) +[![dependency status](https://deps.rs/repo/github/jcornaz/benimator/status.svg)](https://deps.rs/repo/github/jcornaz/benimator) +[![Build](https://img.shields.io/github/workflow/status/jcornaz/benimator/Build)](https://github.com/jcornaz/benimator/actions?query=workflow%3ABuild+branch%3Amain) + +A sprite sheet animation plugin for [bevy](https://bevyengine.org) + + +## Features + +* A `SpriteSheetAnimation` component to automatically update the indices of the `TextureAtlasSprite` in the same entity +* An animation is playing if, and only if a `Play` component is present in the entity + * Simply remove/insert the `Play` component to pause/resume an animation +* The animation can be defined from an index-range, or an arbitrary list of indices +* Each frame may have a different duration + + +## Usage + +```rust +fn main() { + App::build() + .add_plugins(DefaultPlugins) + .add_plugin(AnimationPlugin) // <-- Add the plugin + .add_startup_system(spawn.system()) + .run(); +} + +fn spawn( + mut commands: Commands, + asset_server: Res, + mut textures: ResMut>, +) { + // Don't forget the camera ;-) + commands.spawn_bundle(OrthographicCameraBundle::new_2d()); + + commands + // Spawn a bevy sprite-sheet + .spawn_bundle(SpriteSheetBundle { + texture_atlas: textures.add(TextureAtlas::from_grid(asset_server.load("coin.png"), Vec2::new(16.0, 16.0), 5, 1)), + transform: Transform::from_scale(Vec3::splat(10.0)), + ..Default::default() + }) + // Insert the animation component + // Here we use an index-range (from 0 to 4) where each frame has the same duration + .insert(SpriteSheetAnimation::from_range(0..=4, Duration::from_millis(100))) + // Start the animation immediately. Remove this component in order to pause the animation. + .insert(Play); +} +``` + +Here is the result: + +![Example result](docs/coin.gif) + +For more details see the [documentation](https://docs.rs/benimator) + + +## Installation + +Add to `Cargo.toml`: + +```toml +benimator = "0.1.0" +``` + +## Bevy Version Compatibility + +| bevy | benimator | +|------|------------| +| 0.5 | >= 0.1 | + + +## Contribute / Contact + +You can open issues/discussions here, or you can discuss with me (`Jomag#2675`) in +the [bevy discord](https://discord.com/invite/gMUk5Ph) diff --git a/docs/coin.gif b/docs/coin.gif new file mode 100644 index 0000000000000000000000000000000000000000..02bf2ef9fd0ea70994ee9037b4f639fb38d35530 GIT binary patch literal 18043 zcmeI(Wl&t(-X?G?c+db19SAOs2A4ocAUNbeg1cMr1SdfocXt}?Zrt77gS)$1aOpX7 z?|G}li$_mgRaFjlM{UY(2lTZsX~oPtEGYJ!kJQo z&JarZnxeT%iwU^yU`_Ett^LM8x_oWPQlsm|{?cG=X+M%TDh`!GU72C~&t@vUAy zl5jeCywjwE&A~ucyY3;kGPB}zi7!uKs^87W^AwGxyi_l(rd4(I!IZq;eHQAR4wi=- zU2J=+tmm&3o9gUV+s*L=M$&}NH{T`-WG>$e{Ye~$S@+sJx(^;MRJ$OqTZlYw_BQ$p zcz-RsnO$5>kHLZY3j! zz)S;iQi8XWt&C*NOl@2COw-gyZZ*=KRf2btzMc1)XUaao%#Hkr8gd{$^NG-G9&W3o z;K+{+*|`C_>Xz|cs+Mg9Szr(x8VIjuiBDG%+J_e=q)fv;=Ogau3#)whL0V;uEY>mA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uxmjJ|r;)FE{~>FB4Au;(=>BN&rQYjH3X7p*1{@n@(!H@*ru2b)wXpE@q|j z5cQ#T(#D%^u88t5bA=6xg_|D1k@5(au$2F(HtHE`JY$V#tnrLBp0UO=)_BGm|A%FK z#v0F9;~8r_V~uC5@r*T|vBv+`R}`MH#xvG<#v0F9;~8r_V~uC5@r*T|vBopjc*Yw4 a(=H-EV~uC5@r*T|vBopj_>aLFBL53u>w-1_ literal 0 HcmV?d00001 diff --git a/examples/demo.rs b/examples/readme.rs similarity index 50% rename from examples/demo.rs rename to examples/readme.rs index 97bdbc2..1edf099 100644 --- a/examples/demo.rs +++ b/examples/readme.rs @@ -4,42 +4,40 @@ use bevy::prelude::*; use benimator::*; -#[bevy_main] fn main() { App::build() .add_plugins(DefaultPlugins) - .add_plugin(AnimationPlugin) - .add_startup_system(spawn_camera.system()) - .add_startup_system(spawn_coin.system()) + .add_plugin(AnimationPlugin) // <-- Add the plugin + .add_startup_system(spawn.system()) .run(); } -fn spawn_coin( +fn spawn( mut commands: Commands, asset_server: Res, mut textures: ResMut>, ) { - let texture = asset_server.load("coin.png"); - let texture_atlas = textures.add(TextureAtlas::from_grid( - texture, - Vec2::new(16.0, 16.0), - 5, - 1, - )); + // Don't forget the camera ;-) + commands.spawn_bundle(OrthographicCameraBundle::new_2d()); commands + // Spawn a bevy sprite-sheet .spawn_bundle(SpriteSheetBundle { - texture_atlas, + texture_atlas: textures.add(TextureAtlas::from_grid( + asset_server.load("coin.png"), + Vec2::new(16.0, 16.0), + 5, + 1, + )), transform: Transform::from_scale(Vec3::splat(10.0)), ..Default::default() }) + // Insert the animation component + // Here we use an index-range (from 0 to 4) where each frame has the same duration .insert(SpriteSheetAnimation::from_range( 0..=4, Duration::from_millis(100), )) + // Start the animation immediately. Remove this component in order to pause the animation. .insert(Play); } - -fn spawn_camera(mut commands: Commands) { - commands.spawn_bundle(OrthographicCameraBundle::new_2d()); -} diff --git a/src/lib.rs b/src/lib.rs index 866a836..8afb1f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,7 @@ //! fn spawn(mut commands: Commands) { //! commands //! .spawn_bundle(SpriteSheetBundle { -//! // TODO: Configure your sprite sheet +//! // TODO: Configure the sprite sheet //! ..Default::default() //! }) //! // Insert the animation component