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

Author Topic: local mouse position  (Read 257 times)

0 Members and 1 Guest are viewing this topic.

TheHobHobbit

  • Newbie
  • *
  • Posts: 1
    • View Profile
local mouse position
« 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";

Hapax

  • Hero Member
  • *****
  • Posts: 2935
  • My number of posts is shown in hexadecimal.
    • View Profile
Re: local mouse position
« Reply #1 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
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter