File tree 3 files changed +50
-0
lines changed
3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,10 @@ path = "examples/2d/contributors.rs"
119
119
name = " many_sprites"
120
120
path = " examples/2d/many_sprites.rs"
121
121
122
+ [[example ]]
123
+ name = " move_sprite"
124
+ path = " examples/2d/move_sprite.rs"
125
+
122
126
[[example ]]
123
127
name = " 2d_rotation"
124
128
path = " examples/2d/rotation.rs"
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 @@ -84,6 +84,7 @@ Example | File | Description
84
84
--- | --- | ---
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
+ ` move_sprite ` | [ ` 2d/move_sprite.rs ` ] ( ./2d/move_sprite.rs ) | Changes the transform of a sprite.
87
88
` mesh2d ` | [ ` 2d/mesh2d.rs ` ] ( ./2d/mesh2d.rs ) | Renders a 2d mesh
88
89
` mesh2d_manual ` | [ ` 2d/mesh2d_manual.rs ` ] ( ./2d/mesh2d_manual.rs ) | Renders a custom mesh "manually" with "mid-level" renderer apis.
89
90
` rect ` | [ ` 2d/rect.rs ` ] ( ./2d/rect.rs ) | Renders a rectangle
You can’t perform that action at this time.
0 commit comments