pub fn mouse_wheel_system(
    time: Res<Time>,
    mut state: ResMut<State>,
    mut scroll_state: ResMut<ScrollState>,
    mouse_wheel: Res<Events<MouseWheel>>,
    mut query: Query<&mut ScrollTimer>, // timer samples every .1 seconds
) {
    for mut timer in &mut query.iter() {
        timer.0.tick(time.delta_seconds);
        if timer.0.finished {
            for event in state.mouse_wheel_event_reader.iter(&mouse_wheel) {
                let mw: &MouseWheel = event.into();

                // scale by whole numbers
                scroll_state.y = (scroll_state.y + mw.y).round();
                scroll_state.x = (scroll_state.x + mw.x).round();

                timer.0.reset()
            }
        } else {
            scroll_state.y = 0.;
            scroll_state.x = 0.;
        }
    }
}
/// System to sample mouse wheel events and update athe ScrollState
/// resource that can be used by other systems.
System to sample mouse wheel events and update athe ScrollState
resource that can be used by other systems.
System to sample mouse wheel events and update athe ScrollState resource that can be used by other systems .
pub fn mouse_wheel_system(
    time: Res<Time>,
    mut state: ResMut<State>,
    mut scroll_state: ResMut<ScrollState>,
    mouse_wheel: Res<Events<MouseWheel>>,
    mut query: Query<&mut ScrollTimer>, // timer samples every .1 seconds
) {
    for mut timer in &mut query.iter() {
        timer.0.tick(time.delta_seconds);
        if timer.0.finished {
            for event in state.mouse_wheel_event_reader.iter(&mouse_wheel) {
                let mw: &MouseWheel = event.into();
                // scale by whole numbers
                scroll_state.y = (scroll_state.y + mw.y).round();
                scroll_state.x = (scroll_state.x + mw.x).round();
                timer.0.reset()
            }
        } else {
            scroll_state.y = 0.;
            scroll_state.x = 0.;
        }
    }
}
pub fn mouse_wheel_system ( time : Res < Time > , mut state : ResMut < State > , mut scroll_state : ResMut < ScrollState > , mouse_wheel : Res < Events < MouseWheel > > , mut query : Query < & mut ScrollTimer > , // timer samples every .1 seconds ) { for mut timer in & mut query . iter ( ) { timer . 0 . tick ( time . delta_seconds ) ; if timer . 0 . finished { for event in state . mouse_wheel_event_reader . iter ( & mouse_wheel ) { let mw : & MouseWheel = event . into ( ) ; // scale by whole numbers scroll_state . y = ( scroll_state . y + mw . y ) . round ( ) ; scroll_state . x = ( scroll_state . x + mw . x ) . round ( ) ; timer . 0 . reset ( ) } } else { scroll_state . y = 0. ; scroll_state . x = 0. ; } } }
System to sample mouse wheel events and update athe ScrollState
resource that can be used by other systems.
System to sample mouse wheel events and update athe ScrollState resource that can be used by other systems .
time
Res<Time>
state
ResMut<State>
scroll_state
ResMut<ScrollState>
mouse_wheel
Res<Events<MouseWheel>>
query
Query<&mut ScrollTimer>
time
Res<Time>
state
ResMut<State>
scroll_state
ResMut<ScrollState>
mouse_wheel
Res<Events<MouseWheel>>
query
Query<&mut ScrollTimer>