Mouse position with screen scrolling in SFML

后端 未结 1 1828
小鲜肉
小鲜肉 2021-01-07 14:07

Im trying to create a block placement with snap to grid. Everything is working, and in my head this should update the position of the mouse relative to the window each frame

相关标签:
1条回答
  • 2021-01-07 15:10

    You need to call window.mapPixelToCoords() to transform your pixel position to the coordinate system of your view.

    sf::Vector2i pixel_pos = sf::Mouse::getPosition(window.mywindow);
    sf::Vector2f coord_pos = window.mywindow.mapPixelToCoords(pixel_pos);
    

    And as a general advice: Don't use public class members - mywindow and playerSprite should not be accessible from the outside.

    0 讨论(0)
提交回复
热议问题