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

Author Topic: trouble getting the position of the mouse in the window c++ sfml  (Read 1713 times)

0 Members and 1 Guest are viewing this topic.

SSLukeY

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
I'm making a buttonClick() function in a different class, I need to pass the window and event into the function from the main(), but when I try to get the position of the mouse in the window passed in the function, it gives me a error: no instance overloaded function sf::Mouse.getPosition matches the argument list, I have no idea what's going on, any help?

here is the code:
void screenManager::buttonClick(RenderTarget &window, Event &event) {
if (mouse.getPosition(window).x > startButtonText.getGlobalBounds().left && mouse.getPosition(window).x < startButtonText.getGlobalBounds().left + startButtonText.getGlobalBounds().width && mouse.getPosition(window).y > startButtonText.getGlobalBounds().top && mouse.getPosition(window).y < startButtonText.getGlobalBounds().top + startButtonText.getGlobalBounds().width - 250) {
    startButtonText.setColor(Color::White);
}
else {
    startButtonText.setColor(Color::Green);
}

if (mouse.getPosition(window).x > startButtonText.getGlobalBounds().left && mouse.getPosition(window).x < startButtonText.getGlobalBounds().left + startButtonText.getGlobalBounds().width && mouse.getPosition(window).y > startButtonText.getGlobalBounds().top && mouse.getPosition(window).y < startButtonText.getGlobalBounds().top + startButtonText.getGlobalBounds().width - 250 && event.type == Event::MouseButtonPressed && event.key.code == Mouse::Left) {
    display = false;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: trouble getting the position of the mouse in the window c++ sfml
« Reply #1 on: June 17, 2016, 09:23:01 pm »
Quote
I have no idea what's going on
Really? The compiler tells you that the argument doesn't match, so a quick look at the documentation and you see that Mouse::getPosition takes a sf::Window, not a sf::RenderTarget. You see, it was pretty simply actually ;)
Laurent Gomila - SFML developer

SSLukeY

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: trouble getting the position of the mouse in the window c++ sfml
« Reply #2 on: June 17, 2016, 09:56:08 pm »
oops I didn't think what i was doing at all thanks