SFML community forums

Help => General => Topic started by: SSLukeY on June 17, 2016, 09:09:08 pm

Title: trouble getting the position of the mouse in the window c++ sfml
Post by: SSLukeY on June 17, 2016, 09:09:08 pm
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;
}
Title: Re: trouble getting the position of the mouse in the window c++ sfml
Post by: Laurent 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 ;)
Title: Re: trouble getting the position of the mouse in the window c++ sfml
Post by: SSLukeY on June 17, 2016, 09:56:08 pm
oops I didn't think what i was doing at all thanks