Advertisement
Felanpro

move character with mouse movement

Mar 21st, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. int width = 800;
  2. int height = 600;
  3.  
  4. int x = width/2;
  5. int y = height/2;
  6.  
  7. int main()
  8. {
  9.     sf::RenderWindow window(sf::VideoMode(width, height), "Generic name for a window");
  10.     window.setFramerateLimit(60);
  11.  
  12.     sf::CircleShape circle(30.f);
  13.     circle.setFillColor(sf::Color::Black);
  14.     //circle.setOutlineThickness(15.f);
  15.     //circle.setOutlineColor(sf::Color::Green);
  16.  
  17.     sf::Event event;
  18.     while (window.isOpen())
  19.     {
  20.         window.clear(sf::Color::White);
  21.  
  22.         while (window.pollEvent(event))
  23.         {
  24.             if ((event.type == sf::Event::Closed) || (event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
  25.                 window.close();
  26.  
  27.  
  28.             if(event.type == sf::Event::MouseMoved)
  29.             {
  30.                 x = event.mouseMove.x;
  31.                 y = event.mouseMove.y;
  32.                 circle.setPosition(x, y);
  33.             }
  34.         }
  35.  
  36.         window.draw(circle);
  37.  
  38.         window.display();
  39.     }
  40.  
  41.     int pause; cin >> pause; //Pause the program
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement