I made this piece of code to display the mouse position on the screen but it doesn't work.
sf::String GetString()
{
sf::Input mouseInput;
std::stringstream out;
out << "x: " << mouseInput.GetMouseX() << "\ny: " << mouseInput.GetMouseY();
std::string myString;
myString = out.str();
sf::Unicode::Text myText(myString);
sf::String thisString(myText, sf::Font::GetDefaultFont(), 15);
return thisString;
}
int main()
{
sf::RenderWindow myWindow(sf::VideoMode(800, 600), "myWindow");
while (myWindow.IsOpened())
{
sf::Event myEvent;
while (myWindow.GetEvent(myEvent))
{
if (myEvent.Type == sf::Event::MouseMoved)
{
myWindow.Clear();
myWindow.Draw(GetString());
}
if (myEvent.Type == sf::Event::Closed)
myWindow.Close();
}
myWindow.Display();
}
return 0;
}
The problem is that the string that the numbers that should display the position, are always 0.
x: 0
y: 0
Whats wrong here?