added dragging

master
mitchellhansen 5 years ago
parent a403d13f41
commit c3a2c45e21

@ -38,7 +38,7 @@ impl Input {
self.held_mouse.insert(button.clone() as u8);
},
Event::MouseButtonReleased { button, x, y } => {
self.held_mouse.insert(button.clone() as u8);
self.held_mouse.remove(&(button.clone() as u8));
},
_ => {}
}

@ -15,7 +15,9 @@ use sfml::graphics::{
};
use sfml::system::*;
use sfml::window::{Event, Key, Style};
use sfml::window::mouse::Button;
use sfml::window::mouse::*;
use sfml::window::mouse;
use vulkano::sync;
use std::sync::Arc;
@ -84,7 +86,10 @@ fn main() {
let mut accumulator_time: f32 = 0.0;
let mut current_time: f32 = timer.elap_time();
let mut mouse_xy = Vector2i::new(0,0);
while window.is_open() {
while let Some(event) = window.poll_event() {
match event {
Event::Closed => return,
@ -94,18 +99,13 @@ fn main() {
}
},
Event::MouseButtonPressed { button, x, y } => {
mouse_xy = mouse::desktop_position();
},
Event::MouseWheelScrolled { wheel, delta, x, y } => {
if delta > 0.0 {
println!("{:?}", delta);
println!("{:?}", background_sprite.get_scale());
background_sprite.set_scale(background_sprite.get_scale()+Vector2f::new(0.1,0.1));
background_sprite.set_scale(background_sprite.get_scale()*Vector2f::new(1.1,1.1));
} else {
println!("{:?}", delta);
println!("{:?}", background_sprite.get_scale()+Vector2f::new(-0.1,-0.1));
background_sprite.set_scale(background_sprite.get_scale()+Vector2f::new(-0.1,-0.1));
background_sprite.set_scale(background_sprite.get_scale()*Vector2f::new(0.9,0.9));
}
},
_ => {}
@ -115,6 +115,13 @@ fn main() {
if input.is_mousebutton_held(Button::Left) {
let delta = mouse_xy - mouse::desktop_position();
mouse_xy = mouse::desktop_position();
println!("{:?}", delta);
background_sprite.set_position(
background_sprite.position() - Vector2f::new(delta.x as f32, delta.y as f32)
);
}
elapsed_time = timer.elap_time();

Loading…
Cancel
Save