when my cursor goes out of window my red circle goes to top left corner. Also when I click in the window the red circle goes to extreme left.
#include <SFML/Graphics.hpp>
#include<iostream>
using namespace std;
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Circle Cursor");
sf::CircleShape circle(30);
circle.setOrigin(30,30);
circle.setFillColor(sf::Color::Red);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
switch(event.type)
{
case sf::Event::EventType::MouseMoved:
cout<<event.mouseMove.x <<" : "<<event.mouseMove.y<<endl;
}
}
//if(sf::Event::)
window.clear();
circle.setPosition(event.mouseMove.x, event.mouseMove.y);
window.draw(circle);
window.display();
}
return 0;
}