From 7e6c67edc93f8de8ba056f17b6cb63b5b5407c40 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Wed, 15 Jun 2022 21:30:37 +0200 Subject: [PATCH] Fix pikachu --- src/meshs/default_mesh.rs | 6 +++--- src/state.rs | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) 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),