Skip to content

Commit 68e1a20

Browse files
committed
added move_sprite example
fixed line endings added space for CI changed to enum fixed formating fix formating again added transform to start. removed system
1 parent 7f34ffc commit 68e1a20

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ path = "examples/2d/contributors.rs"
103103
name = "mesh"
104104
path = "examples/2d/mesh.rs"
105105

106+
[[example]]
107+
name = "move_sprite"
108+
path = "examples/2d/move_sprite.rs"
109+
106110
[[example]]
107111
name = "many_sprites"
108112
path = "examples/2d/many_sprites.rs"
@@ -299,10 +303,13 @@ name = "system_chaining"
299303
path = "examples/ecs/system_chaining.rs"
300304

301305
[[example]]
306+
<<<<<<< refs/remotes/bevyengine/trying
302307
name = "system_graph"
303308
path = "examples/ecs/system_graph.rs"
304309

305310
[[example]]
311+
=======
312+
>>>>>>> fixed line endings
306313
name = "system_param"
307314
path = "examples/ecs/system_param.rs"
308315

examples/2d/move_sprite.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use bevy::prelude::*;
2+
3+
fn main() {
4+
App::build()
5+
.add_plugins(DefaultPlugins)
6+
.add_startup_system(setup)
7+
.add_system(sprite_movement)
8+
.run();
9+
}
10+
11+
enum Direction {
12+
Up,
13+
Down,
14+
}
15+
16+
fn setup(
17+
mut commands: Commands,
18+
asset_server: Res<AssetServer>,
19+
mut materials: ResMut<Assets<ColorMaterial>>,
20+
) {
21+
let texture_handle = asset_server.load("branding/icon.png");
22+
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
23+
commands
24+
.spawn_bundle(SpriteBundle {
25+
material: materials.add(texture_handle.into()),
26+
transform: Transform::from_xyz(100., 0., 0.),
27+
..Default::default()
28+
})
29+
.insert(Direction::Up);
30+
}
31+
32+
fn sprite_movement(time: Res<Time>, mut sprite_position: Query<(&mut Direction, &mut Transform)>) {
33+
for (mut logo, mut transform) in sprite_position.iter_mut() {
34+
match *logo {
35+
Direction::Up => transform.translation.y += 150. * time.delta_seconds(),
36+
Direction::Down => transform.translation.y -= 150. * time.delta_seconds(),
37+
}
38+
39+
if transform.translation.y > 200. {
40+
*logo = Direction::Down;
41+
} else if transform.translation.y < -200. {
42+
*logo = Direction::Up;
43+
}
44+
}
45+
}

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Example | File | Description
8585
`contributors` | [`2d/contributors.rs`](./2d/contributors.rs) | Displays each contributor as a bouncy bevy-ball!
8686
`many_sprites` | [`2d/many_sprites.rs`](./2d/many_sprites.rs) | Displays many sprites in a grid arragement! Used for performance testing.
8787
`mesh` | [`2d/mesh.rs`](./2d/mesh.rs) | Renders a custom mesh
88+
`move_sprite` | [`2d/move_sprite.rs`](./2d/move_sprite.rs) | Changes the transform of a sprite.
8889
`sprite` | [`2d/sprite.rs`](./2d/sprite.rs) | Renders a sprite
8990
`sprite_sheet` | [`2d/sprite_sheet.rs`](./2d/sprite_sheet.rs) | Renders an animated sprite
9091
`text2d` | [`2d/text2d.rs`](./2d/text2d.rs) | Generates text in 2d

0 commit comments

Comments
 (0)