Skip to content

Instantly share code, notes, and snippets.

@clooth
Created September 23, 2013 10:51
Show Gist options
  • Save clooth/6668963 to your computer and use it in GitHub Desktop.
Save clooth/6668963 to your computer and use it in GitHub Desktop.
map scroll
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