-
I need to rework my classes for update my little engine but today i'm encountered in an error:
I run those "check" codes for finding the position of the mouse and :
This show the position of the mouse on desktop
sf::Vector2i mousepos = sf::Mouse::getPosition();
This show the position of the mouse on window
sf::Vector2i mousepos = sf::Mouse::getPosition(window);
But what code need I to run for know what is the position of the mouse on my 2D world ?
For example, now the funtion return that my mouse is on position (0,0) (i placed it at left-top) but in my world it's in position (213,352);
How can I find the 2D coords position of mouse with a sf::(mouse ?)::function ?
sfml2 lastest release and windows 7
ty!
-
Use the convertCoords() (http://www.sfml-dev.org/documentation/2.0/classsf_1_1RenderTarget.php#afc047333937f7cb7fe557aec60239233) function of the sf::RenderTarget (i.e. sf::RenderWindow). If you want the transformation for a specific sf::View you can also supply that view as second parameter. ;)
-
mmm
i tried
sf::Vector2i mousepos = sf::Mouse::getPosition(window);
window.convertCoords(mousepos,window.getView());
and without window.getview() too, but still giving wrong coord.
-
convertCoords doesn't transform the given coordinates, it returns a new point.
sf::Vector2f converted = window.convertCoords(mousepos);
Note that calling it with window.getView() is useless, it always takes the current view by default.
-
ty laurent :)