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

Author Topic: GetMouseX() always returning 0  (Read 5390 times)

0 Members and 1 Guest are viewing this topic.

evilertoaster

  • Newbie
  • *
  • Posts: 9
    • View Profile
GetMouseX() always returning 0
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
GetMouseX() always returning 0
« Reply #1 on: February 11, 2008, 08:05:11 am »
Can we see the DoEvents function ?
Laurent Gomila - SFML developer

evilertoaster

  • Newbie
  • *
  • Posts: 9
    • View Profile
GetMouseX() always returning 0
« Reply #2 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;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
GetMouseX() always returning 0
« Reply #3 on: February 11, 2008, 09:18:23 am »
How do you initialize inpt ?
Laurent Gomila - SFML developer

evilertoaster

  • Newbie
  • *
  • Posts: 9
    • View Profile
GetMouseX() always returning 0
« Reply #4 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
GetMouseX() always returning 0
« Reply #5 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();
Laurent Gomila - SFML developer

evilertoaster

  • Newbie
  • *
  • Posts: 9
    • View Profile
GetMouseX() always returning 0
« Reply #6 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

 

anything