SFML community forums

Help => Window => Topic started by: TheHobHobbit on May 02, 2020, 03:01:10 am

Title: local mouse position
Post by: TheHobHobbit on May 02, 2020, 03:01:10 am
so my window is 480x360, making a pixel-style game. just told a sprite to be my new mouse pointer, and hiding the real pointer. this works fine, until I hit the fullscreen button. then the mouse coordinates aren't correct anymore. it's figured out that x0y0 has moved, but the coordinates I'm getting are assuming the screen is still 480x360.

here's all the code that matters to give ya, everything other than the local mouse position is working fine.

sf::RenderWindow window(sf::VideoMode(480, 360), "Hello");

mPos.x = sf::Mouse::getPosition(mainWindow).x;
mPos.y = sf::Mouse::getPosition(mainWindow).y;
    UIsprite.setPosition({mPos.x,mPos.y});
    mainWindow.draw(UIsprite);
    std::cout << mPos.x << "~" << mPos.y << "\n";
Title: Re: local mouse position
Post by: Hapax on May 05, 2020, 11:38:51 pm
You need to convert your mouse position, which is in pixel co-ordinates, to the position inside your view ("world" co-ordinates):
https://www.sfml-dev.org/tutorials/2.5/graphics-view.php#coordinates-conversions