SFML community forums

Help => Window => Topic started by: rpaggi on April 15, 2014, 03:49:00 am

Title: Position the mouse changing when I move the View
Post by: rpaggi on April 15, 2014, 03:49:00 am
Hi,

I have an problem, i start my Window and i get the mouse positions( sf::Mouse::getPosition() ), when i move my view the mouse positions changes too.
Have anyway to keep the mouse positions independent of View movement?

Sorry my bad English, thanks
Title: Re: Position the mouse changing when I move the View
Post by: G. on April 15, 2014, 05:31:51 am
sf::Mouse::getPosition() gives you the position on the mouse on the screen. So it is already independent of any sf::View you might be using. It's even independent of the window position unless your provide a window as an argument to getPosition.
Title: Re: Position the mouse changing when I move the View
Post by: Ixrec on April 15, 2014, 08:05:45 am
I don't know what you mean by "keep the mouse positions independent of View movement" (as G said, they already are independent) but the functions mapPixelToCoords() and mapCoordsToPixel() might be part of the solution.
Title: Re: Position the mouse changing when I move the View
Post by: rpaggi on April 15, 2014, 11:02:50 pm
Hello,

Example:
When i used sf::Mouse::getPosition(), it returned the vector 200, 200
After i used an view.move(10, 20), after this i used again sf::Mouse::getPosition() and it returned the vector 210, 230.

I'm using sfml-tmxloader to use Tiled maps, this can affect this?

Thanks
Title: Re: Position the mouse changing when I move the View
Post by: Ixrec on April 15, 2014, 11:20:54 pm
Assuming you didn't move the mouse yourself between those calls, that does not sound possible.  Can you show us a complete and minimal code example?  We must be misunderstanding your explanation somehow.

I can't imagine tiled maps have anything to do with it.  Like G said, Mouse::getPosition() only gets the position on your monitor.  It has nothing to do with what's being drawn in your window or game world.
Title: Re: Position the mouse changing when I move the View
Post by: rpaggi on April 16, 2014, 02:19:57 am
Sorry guys,
Really works.
Thanks for the help!
Title: Re: Position the mouse changing when I move the View
Post by: jannugimes on May 18, 2014, 07:37:37 am
I have same issue in the past but reading this post I have solved the problem.