File tree 3 files changed +53
-0
lines changed
3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,10 @@ path = "examples/2d/contributors.rs"
103
103
name = " mesh"
104
104
path = " examples/2d/mesh.rs"
105
105
106
+ [[example ]]
107
+ name = " move_sprite"
108
+ path = " examples/2d/move_sprite.rs"
109
+
106
110
[[example ]]
107
111
name = " many_sprites"
108
112
path = " examples/2d/many_sprites.rs"
@@ -299,10 +303,13 @@ name = "system_chaining"
299
303
path = " examples/ecs/system_chaining.rs"
300
304
301
305
[[example ]]
306
+ <<<<<<< refs/remotes/bevyengine/trying
302
307
name = " system_graph"
303
308
path = " examples/ecs/system_graph.rs"
304
309
305
310
[[example ]]
311
+ =======
312
+ >>>>>>> fixed line endings
306
313
name = " system_param"
307
314
path = " examples/ecs/system_param.rs"
308
315
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ Example | File | Description
85
85
` contributors ` | [ ` 2d/contributors.rs ` ] ( ./2d/contributors.rs ) | Displays each contributor as a bouncy bevy-ball!
86
86
` many_sprites ` | [ ` 2d/many_sprites.rs ` ] ( ./2d/many_sprites.rs ) | Displays many sprites in a grid arragement! Used for performance testing.
87
87
` 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.
88
89
` sprite ` | [ ` 2d/sprite.rs ` ] ( ./2d/sprite.rs ) | Renders a sprite
89
90
` sprite_sheet ` | [ ` 2d/sprite_sheet.rs ` ] ( ./2d/sprite_sheet.rs ) | Renders an animated sprite
90
91
` text2d ` | [ ` 2d/text2d.rs ` ] ( ./2d/text2d.rs ) | Generates text in 2d
You can’t perform that action at this time.
0 commit comments