diff --git a/Cargo.toml b/Cargo.toml index 9e0b659358b7cc..95df03bd94e2ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -119,6 +119,10 @@ path = "examples/2d/contributors.rs" name = "many_sprites" path = "examples/2d/many_sprites.rs" +[[example]] +name = "move_sprite" +path = "examples/2d/move_sprite.rs" + [[example]] name = "2d_rotation" path = "examples/2d/rotation.rs" diff --git a/examples/2d/move_sprite.rs b/examples/2d/move_sprite.rs new file mode 100644 index 00000000000000..cec9bab4a28017 --- /dev/null +++ b/examples/2d/move_sprite.rs @@ -0,0 +1,45 @@ +use bevy::prelude::*; + +fn main() { + App::build() + .add_plugins(DefaultPlugins) + .add_startup_system(setup) + .add_system(sprite_movement) + .run(); +} + +enum Direction { + Up, + Down, +} + +fn setup( + mut commands: Commands, + asset_server: Res, + mut materials: ResMut>, +) { + let texture_handle = asset_server.load("branding/icon.png"); + commands.spawn_bundle(OrthographicCameraBundle::new_2d()); + commands + .spawn_bundle(SpriteBundle { + material: materials.add(texture_handle.into()), + transform: Transform::from_xyz(100., 0., 0.), + ..Default::default() + }) + .insert(Direction::Up); +} + +fn sprite_movement(time: Res