File tree 1 file changed +5
-3
lines changed
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change 1
- use bevy:: core:: FixedTimestep ;
2
1
use bevy:: prelude:: * ;
2
+ use bevy:: { app:: Events , core:: FixedTimestep } ;
3
3
4
4
/// Events are automatically cleaned up after two frames when intialized via `.add_event`.
5
5
/// To bypass this, you can simply add the Events::<T> resource manually.
@@ -17,7 +17,8 @@ use bevy::prelude::*;
17
17
fn main ( ) {
18
18
App :: build ( )
19
19
. add_plugins ( DefaultPlugins )
20
- . add_event :: < MyEvent > ( )
20
+ // We can't use .add_event or our events will be cleaned up too soon
21
+ . init_resource :: < Events < MyEvent > > ( )
21
22
. add_system (
22
23
event_trigger_system
23
24
. system ( )
@@ -42,14 +43,15 @@ struct MyEvent {
42
43
fn event_trigger_system ( time : Res < Time > , mut my_events : EventWriter < MyEvent > ) {
43
44
my_events. send ( MyEvent {
44
45
message : format ! (
45
- "This event was sent at {}" ,
46
+ "This event was sent at {} milliseconds " ,
46
47
time. time_since_startup( ) . as_millis( )
47
48
)
48
49
. to_string ( ) ,
49
50
} ) ;
50
51
}
51
52
52
53
// reads events as soon as they come in
54
+ // FIXME: stops responding after the first time events are consumed
53
55
fn event_listener_system ( mut events : EventReader < MyEvent > ) {
54
56
for _ in events. iter ( ) {
55
57
info ! ( "I heard an event!" ) ;
You can’t perform that action at this time.
0 commit comments