Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [solved]Problem with string  (Read 2265 times)

0 Members and 1 Guest are viewing this topic.

Devil0150

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
[solved]Problem with string
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[solved]Problem with string
« Reply #1 on: July 28, 2009, 06:12:30 pm »
It's not the correct way to use sf::Input. Please read the tutorial / documentation first.
Laurent Gomila - SFML developer

Devil0150

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
[solved]Problem with string
« Reply #2 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 post.

Thanks anyway.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[solved]Problem with string
« Reply #3 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 ;)
Laurent Gomila - SFML developer

 

anything