Skip to content

Commit

Permalink
docs(examples): Add a demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornaz committed Jun 15, 2021
1 parent e13a69c commit 27bccf4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -20,5 +20,5 @@ bevy_reflect = "^0.5.0"
bevy_sprite = "^0.5.0"

[dev-dependencies]
bevy = { version = "^0.5.0", default-features = false, features = ["render", "bevy_wgpu", "x11"] }
bevy = { version = "^0.5.0", default-features = false, features = ["render", "bevy_wgpu", "x11", "png"] }
rstest = "^0.7.0" # Newer versions are incompatible with bevy 0.5
3 changes: 3 additions & 0 deletions assets/README.md
@@ -0,0 +1,3 @@
# Credits

Coin by [La Red Games](https://laredgames.itch.io/gems-coins-free) (CC0)
Binary file added assets/coin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions examples/demo.rs
@@ -0,0 +1,47 @@
use std::time::Duration;

use bevy::prelude::*;

use animism::*;

#[bevy_main]
fn main() {
App::build()
.add_plugins(DefaultPlugins)
.add_plugin(AnimationPlugin)
.add_startup_system(spawn_camera.system())
.add_startup_system(spawn_coin.system())
.run();
}

fn spawn_coin(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut textures: ResMut<Assets<TextureAtlas>>,
) {
let texture = asset_server.load("coin.png");
let texture_atlas = textures.add(TextureAtlas::from_grid(
texture,
Vec2::new(16.0, 16.0),
5,
1,
));

let frame_duration = Duration::from_millis(100);

commands
.spawn_bundle(SpriteSheetBundle {
texture_atlas,
transform: Transform::from_scale(Vec3::splat(10.0)),
..Default::default()
})
.insert(SpriteSheetAnimation::from_frames(
(0..5)
.map(|index| Frame::new(index, frame_duration))
.collect(),
));
}

fn spawn_camera(mut commands: Commands) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
}

0 comments on commit 27bccf4

Please sign in to comment.