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

Author Topic: Position the mouse changing when I move the View  (Read 3412 times)

0 Members and 1 Guest are viewing this topic.

rpaggi

  • Newbie
  • *
  • Posts: 4
    • View Profile
Position the mouse changing when I move the View
« 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

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Position the mouse changing when I move the View
« Reply #1 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.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Position the mouse changing when I move the View
« Reply #2 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.

rpaggi

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Position the mouse changing when I move the View
« Reply #3 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

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Position the mouse changing when I move the View
« Reply #4 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.

rpaggi

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Position the mouse changing when I move the View
« Reply #5 on: April 16, 2014, 02:19:57 am »
Sorry guys,
Really works.
Thanks for the help!

jannugimes

  • Guest
Re: Position the mouse changing when I move the View
« Reply #6 on: May 18, 2014, 07:37:37 am »
I have same issue in the past but reading this post I have solved the problem.

 

anything