SFML community forums

Help => Window => Topic started by: Devil0150 on July 28, 2009, 06:10:04 pm

Title: [solved]Problem with string
Post by: Devil0150 on July 28, 2009, 06:10:04 pm
I made this piece of code to display the mouse position on the screen but it doesn't work.

Code: [Select]
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?
Title: [solved]Problem with string
Post by: Laurent on July 28, 2009, 06:12:30 pm
It's not the correct way to use sf::Input. Please read the tutorial / documentation first.
Title: [solved]Problem with string
Post by: Devil0150 on July 28, 2009, 06:18:21 pm
I didnt find anything for mouse Input at the Tutorials and I dont understand it very well at the documentation.
But i fixed it reading this (http://www.sfml-dev.org/forum/viewtopic.php?t=1423) post.

Thanks anyway.
Title: [solved]Problem with string
Post by: Laurent on July 28, 2009, 06:23:10 pm
The tutorial to read is this one
http://www.sfml-dev.org/tutorials/1.5/window-events.php
Section "Getting real-time inputs".

The documentation will soon be updated to make this kind of things clearer ;)