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

Author Topic: SFML moving view bug?  (Read 1549 times)

0 Members and 1 Guest are viewing this topic.

MrMode

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML moving view bug?
« on: January 11, 2020, 03:12:34 pm »
Hello,
I am now  creating level editor for my game where u can make maps/levels etc. for a game I am making.
The problem is that then I move the view HUD moves as it should, by that I mean it "stays"  locked to a screen and everything seems fine, but then I try to press a sprite it does nothing, but then I tried to press around the sprite not the sprite it self and it works. It seems like sprite picture moved correctly but box which checks that if sprite is clicked(Don't know how it works just guessing) moved less or more and now is in incorrect place. Did anyone encountered this problem before?

Thanks in advance

if (_mousePosition.x > 0 && _mousePosition.x < _wSize.x && _mousePosition.y > 0 && _mousePosition.y < _wSize.y)
   {
      if (_mousePosition.x > _data->window.getSize().x - 20)
      {
         _view.move(300.0f * dt, 0);
         MoveHudAndItsElementsRight(dt);
      }
      else if (_mousePosition.x < 20)
      {
         _view.move(-300.0f * dt, 0);
         MoveHudAndItsElementsLeft(dt);

      }
      else if (_mousePosition.y < 20)
      {
         _view.move(0, -300.0f * dt);
         MoveHudAndItsElementsUp(dt);

      }
      else if (_mousePosition.y > _data->window.getSize().y - 20)
      {                                       
         _view.move(0, 300.0f * dt);
         MoveHudAndItsElementsDown(dt);

      }
   }
   _data->window.setView(_view);
}

void MapMaker::MoveHudAndItsElementsUp(float dt)
{
   _mainBar.move(0, -300.0f * dt);
   _tilesSelectBar.setPosition(_mainBar.getPosition().x, _mainBar.getPosition().y - _tilesSelectBar.getLocalBounds().height);
   _objectsSelectBar.setPosition(_tilesSelectBar.getPosition().x + _tilesSelectBar.getLocalBounds().width, _tilesSelectBar.getPosition().y);
   _greenTile1.setPosition(_mainBar.getPosition().x + 10, _mainBar.getPosition().y + 10);
   _rockTile1.setPosition(_greenTile1.getPosition().x + _greenTile1.getLocalBounds().width, _greenTile1.getPosition().y);

}
« Last Edit: January 11, 2020, 03:15:25 pm by MrMode »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: SFML moving view bug?
« Reply #1 on: January 11, 2020, 04:28:28 pm »
Please use [code=cpp][/code] tags when posting code and read the sub-forum descriptions before creating threads in unrelated sub-forums.

If you want to translate mouse positions from screen space to world space, you can use the function mapPixelToCoords. Other than that, makes sure you check your math with a debugger and some pen & paper. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MrMode

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: SFML moving view bug?
« Reply #2 on: January 11, 2020, 04:46:25 pm »
Thank you for quick replay!
It works now