diff --git a/src/meshs/default_mesh.rs b/src/meshs/default_mesh.rs index 0462d2e..3eba4e8 100644 --- a/src/meshs/default_mesh.rs +++ b/src/meshs/default_mesh.rs @@ -94,9 +94,9 @@ impl DefaultMesh { } } - pub fn toggle(&mut self) { - self.toggle = !self.toggle; - if self.toggle { + pub fn toggle(&mut self, toggle: bool) { + self.toggle = toggle; + if !self.toggle { self.mesh.texture_bind_group = Some(self.texture1_bind_group.clone()); } else { self.mesh.texture_bind_group = Some(self.texture2_bind_group.clone()); diff --git a/src/state.rs b/src/state.rs index 32c7444..2d3ee78 100644 --- a/src/state.rs +++ b/src/state.rs @@ -5,7 +5,7 @@ use super::render::{ }; use wgpu::util::DeviceExt; use winit::{ - event::{KeyboardInput, VirtualKeyCode, WindowEvent}, + event::{KeyboardInput, VirtualKeyCode, WindowEvent, ElementState}, window::Window, }; @@ -297,14 +297,16 @@ impl State { WindowEvent::KeyboardInput { input: KeyboardInput { + state, virtual_keycode: Some(keycode), .. }, .. } => { + let is_pressed = *state == ElementState::Pressed; match keycode { VirtualKeyCode::Space => { - self.mesh.toggle(); + self.mesh.toggle(is_pressed); true } _ => self.camera_controller.process_events(event),