SFML community forums

Help => General => Topic started by: sec_goat on November 23, 2011, 09:59:30 pm

Title: SFML 2.0 sf::Mouse::GetPosition() returning wierd coords.
Post by: sec_goat 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!
Title: SFML 2.0 sf::Mouse::GetPosition() returning wierd coords.
Post by: sec_goat 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;

        }
}