Skip to content

Instantly share code, notes, and snippets.

@kim366
Created October 20, 2016 18:14
Show Gist options
  • Save kim366/f605c0a6cb7597b8e253a0ef1ace2e23 to your computer and use it in GitHub Desktop.
Save kim366/f605c0a6cb7597b8e253a0ef1ace2e23 to your computer and use it in GitHub Desktop.
Move Background in Opposite Direction so it looks like Player is Moving to stop Player from going in a circle
// See RotateToMouse.cpp for definition of delta
sf::Vector2f normalizedDelta(delta / hypot(delta.x, delta.y));
if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
background.move(sf::Vector2f(-normalizedDelta.x, -normalizedDelta.y));
if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
background.move(sf::Vector2f(normalizedDelta.x, normalizedDelta.y));
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
background.move(sf::Vector2f(-normalizedDelta.y, normalizedDelta.x));
if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
background.move(sf::Vector2f(normalizedDelta.y, -normalizedDelta.x));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment