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

Author Topic: SFML 2.0 sf::Mouse::GetPosition() returning wierd coords.  (Read 5168 times)

0 Members and 1 Guest are viewing this topic.

sec_goat

  • Newbie
  • *
  • Posts: 17
    • View Profile
SFML 2.0 sf::Mouse::GetPosition() returning wierd coords.
« on: November 23, 2011, 09:59:30 pm »
Hello all,

I am trying to return my mouse cursor position so I can check to see if something is clicked or not.

Currently this is my code
Code: [Select]

 sf::Event currentEvent;
    while(m_GameWindow.PollEvent(currentEvent))
    {
        if(currentEvent.Type == sf::Event::MouseButtonPressed)
        {
            sf::Vector2i mouse_pos = sf::Mouse::GetPosition();
            bool clicked = TravelBoard.CheckForTilesClicked(mouse_pos);
            std::cout<<clicked<<std::endl;

        }
}


when I print my pos.x and pos.y they are much higher than they should be, for instance if I click as close to the top left of the screen as possible i get something like (1028,698) instead of something closer to (0,0).

What am i doing wrong in this instance to get a larger position than the one I should be getting?

Thanks!

sec_goat

  • Newbie
  • *
  • Posts: 17
    • View Profile
SFML 2.0 sf::Mouse::GetPosition() returning wierd coords.
« Reply #1 on: November 23, 2011, 10:01:46 pm »
Well Don't I feel stupid!

If you don't feed the GetPosition() a RenderWindow it gives you coords relative to your overall window position and not the applications position.

Code: [Select]

sf::Event currentEvent;
    while(m_GameWindow.PollEvent(currentEvent))
    {
        if(currentEvent.Type == sf::Event::MouseButtonPressed)
        {
            sf::Vector2i mouse_pos = sf::Mouse::GetPosition(sf::RenderWindow);
            bool clicked = TravelBoard.CheckForTilesClicked(mouse_pos);
            std::cout<<clicked<<std::endl;

        }
}