SFML community forums

Help => Window => Topic started by: evilertoaster on February 11, 2008, 05:48:52 am

Title: GetMouseX() always returning 0
Post by: evilertoaster on February 11, 2008, 05:48:52 am
Per Subject-
I'm trying to make the current mouse position display in my render window for debuging purposes.
Essentially I have this for my main loop-
Code: [Select]

sf::Input inpt;
sf::String text("","arial.ttf",16.f);
while (1)
{

text.SetText(Convert::toString(inpt.GetMouseX())); //custom conversion works fine, GetMouseX only returns a 0
DoEvents(App); //handles things like window closing ect.
App.Draw(sprScreen); //my main screen
App.Draw(text)
App.Display();
}


Short of posting all the code here, is there anything inherently wrong with trying to get the mouse coordiantes this way?
Title: GetMouseX() always returning 0
Post by: Laurent on February 11, 2008, 08:05:11 am
Can we see the DoEvents function ?
Title: GetMouseX() always returning 0
Post by: evilertoaster on February 11, 2008, 08:13:47 am
sure thing-

Code: [Select]
bool DoEvents(sf::RenderWindow &App)
{
sf::Event Event;
while (App.GetEvent(Event))
{
   if (Event.Type == sf::Event::Closed)
exit(0);
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
exit(0);
}
return true;
}
Title: GetMouseX() always returning 0
Post by: Laurent on February 11, 2008, 09:18:23 am
How do you initialize inpt ?
Title: GetMouseX() always returning 0
Post by: evilertoaster on February 11, 2008, 09:50:23 am
the first line of code on my intial post is the first and only time I initalize it.
Title: GetMouseX() always returning 0
Post by: Laurent on February 11, 2008, 10:47:44 am
Really ? So that explains the behavior.

Try this instead ;)
Code: [Select]
const sf::Input& inpt = App.GetInput();
Title: GetMouseX() always returning 0
Post by: evilertoaster on February 11, 2008, 09:21:07 pm
Works like I wanted. Thanks Laurent.
Actually, thats more what I wanted initially I think...
I kept trying
Code: [Select]
sf::Input::GetMouseX() but I beleive
Code: [Select]
App.GetInput().GetMouseX() is what I was after  :?
Although now looking at it maybe I'll just declare a variable like....
Well anyways, thanks agian  :D