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

Author Topic: Double view and mouse position[SOLVED]  (Read 1841 times)

0 Members and 1 Guest are viewing this topic.

Birdron

  • Newbie
  • *
  • Posts: 17
    • View Profile
Double view and mouse position[SOLVED]
« on: August 11, 2015, 04:00:34 pm »
Hi,
   
   window.clear();

   //Render the sprites
   window.setView(MainView);
   window.draw(Hero);

   //Render others
   window.setView(GuiView);
   if(_dragging)
      window.draw(Box);

   window.display();
   
   The problem is, if I zoom the MainView, the mouse picking no longer works. But if I remove the GuiView, mouse picking works. How do I update the bounds of the Hero sprite after zooming out the MainView, so that I can pick it with mouse?

Thanks in advance.
« Last Edit: August 11, 2015, 07:27:28 pm by Birdron »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile

Birdron

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Double view and mouse position
« Reply #2 on: August 11, 2015, 04:26:21 pm »
This is how I am using my mouse pick,
Code: [Select]
mMousePos = sf::Mouse::getPosition(*this);
mWorldPos = mapPixelToCoords(static_cast<sf::Vector2i>(mMousePos));
And the picking function,
Code: [Select]
bool Entity::isPointInside(const sf::Vector2f& point)
{
    if(mSprite.getGlobalBounds().contains(point))
        return true;

    return false;
}

Thank you.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Double view and mouse position
« Reply #3 on: August 11, 2015, 04:30:38 pm »
By default, mapPixelToCoords uses the current view. If you want to convert the coordinates using view which is not the active one, you can pass it as an additional argument to the function.
http://www.sfml-dev.org/documentation/2.3.1/classsf_1_1RenderTarget.php#a46eb08f775dd1420d6207ea87dde6e54
If it works when you remove the other view, you're probably not converting to the right view.

But you already did that 2 months 1 year ago. ???
« Last Edit: August 11, 2015, 04:55:20 pm by G. »

Birdron

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Double view and mouse position
« Reply #4 on: August 11, 2015, 04:40:55 pm »
Sorry, I almost forgot about my older posts :P. It was one year ago and I don't have that pc anymore, so couldn't remember that.

Thank you for the reply