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

Author Topic: View and rectangle "hitbox" problem  (Read 2802 times)

0 Members and 2 Guests are viewing this topic.

HarmonixxGames

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
View and rectangle "hitbox" problem
« on: February 05, 2021, 10:12:26 am »
Hey, i have really confusing problem. i have just created a button class, and it work fine but when i use view move() method button is moving, but click hitbox is still staying in the same position. I am new at sfml and i have no idea how to solve it.

In the attachment are class .h, .cpp files and main.cpp file.

Help ;c

PS: Sorry for my English

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: View and rectangle "hitbox" problem
« Reply #1 on: February 05, 2021, 11:01:09 am »
sf::Mouse::getPosition returns coordinates relative to the window, not to the view. You need to translate these coordinates with window.mapPixelToCoords, before doing your click test.
Laurent Gomila - SFML developer

HarmonixxGames

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: View and rectangle "hitbox" problem
« Reply #2 on: February 05, 2021, 11:43:58 am »
Ye but how can i do that? when i am doing that:

sf::Vector2i pixelPos = sf::Mouse::getPosition(app);
sf::Vector2f worldPos = app.mapPixelToCoords(pixelPos);

nothing happen. I added that line:
button.setButtonPosition(worldPos.x,worldPos.y);
but now my button is always at cursor position

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: View and rectangle "hitbox" problem
« Reply #3 on: February 05, 2021, 12:25:56 pm »
"worldPos" is the mouse position, translated to the same coordinates system as your button. It replaces "sf::Mouse::getPosition(window)" in Button::isButtonClicked.

If you don't understand what you're doing, take some time to think about it. And if you still don't get it, don't hesitate to ask for more explanations.
Laurent Gomila - SFML developer

HarmonixxGames

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: View and rectangle "hitbox" problem
« Reply #4 on: February 05, 2021, 01:48:28 pm »
Ok thank you, i had to read your reply ten times  but i did it. :)