1
Graphics / Check if sf::RectangleShape contains mouse global bounds?
« on: May 30, 2016, 10:44:37 pm »
Hi,
I want to check if an sf::Shape contains the mouse's global bounds (and if left mouse button is clicked), and created the function below:
However it says sf::RectangleShape has no member contains. How would I do this or do I have to do it the longer way by checking if the cursor is within the shape dimensions?
I want to check if an sf::Shape contains the mouse's global bounds (and if left mouse button is clicked), and created the function below:
bool isRectClicked(sf::RectangleShape &rect, sf::RenderWindow &window) {
sf::IntRect rect(rect.getPosition().x, rect.getPosition().y, rect.getGlobalBounds().width,
rect.getGlobalBounds().height);
if (rect.contains(sf::Mouse::getPosition(window)) && (sf::Mouse::isButtonPressed(sf::Mouse::Left))) {
return true;
}
return false;
}
sf::IntRect rect(rect.getPosition().x, rect.getPosition().y, rect.getGlobalBounds().width,
rect.getGlobalBounds().height);
if (rect.contains(sf::Mouse::getPosition(window)) && (sf::Mouse::isButtonPressed(sf::Mouse::Left))) {
return true;
}
return false;
}
However it says sf::RectangleShape has no member contains. How would I do this or do I have to do it the longer way by checking if the cursor is within the shape dimensions?