Created
October 20, 2016 18:14
-
-
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
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
// 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