Created
September 23, 2013 10:51
-
-
Save clooth/6668963 to your computer and use it in GitHub Desktop.
map scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto panMapLeft = [&mapView] (float speed, float time) { mapView.move(-speed * time, 0.f); }; | |
auto panMapRight = [&mapView] (float speed, float time) { mapView.move(speed * time, 0.f); }; | |
auto panMapUp = [&mapView] (float speed, float time) { mapView.move(0.f, -speed * time); }; | |
auto panMapDown = [&mapView] (float speed, float time) { mapView.move(0.f, speed * time); }; | |
// Map scroll | |
float mapScrollSpeed = 1000.f; // The speed of the scrolling | |
if (event.type == sf::Event::KeyPressed) | |
{ | |
// Pan left | |
if (event.key.code == sf::Keyboard::A) panMapLeft(mapScrollSpeed, elapsedTime.asSeconds()); | |
// Pan right | |
if (event.key.code == sf::Keyboard::D) panMapRight(mapScrollSpeed, elapsedTime.asSeconds()); | |
// Pan up | |
if (event.key.code == sf::Keyboard::W) panMapUp(mapScrollSpeed, elapsedTime.asSeconds()); | |
// Pan up | |
if (event.key.code == sf::Keyboard::S) panMapDown(mapScrollSpeed, elapsedTime.asSeconds()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment