Why don't you show us what you already got? :)
It's a pretty easy problem and all these other threads on the forum explain it just fine, so you must have a problem in understanding it somehow.
i solved this with
if (sprite.getPosition().x <= Mouse::getPosition().x + 100 && sprite.getPosition().x >= Mouse::getPosition().x - 100 && sprite.getPosition().y <= Mouse::getPosition().y +100 && sprite.getPosition().y >= Mouse::getPosition -100)
{
//code goes here
}
but this only checks a hitbox of 200 + 200, if i want to change the hitbox, i could change the numbers, but it the hitbox does not depend on the actual size of the sprite/texture. i want to use this in a class and have multiple objects of this class, some with an other size than others.
1. Get the position of a click.
2. Get coordinates of a sprite.
3. Check if click position was inside those coordinates.
but wouldnt this only work if i clicked the exact origin?
Santus was nearly right, instead of the position of the object you need to get its global bounding box.
And in case you adjust the view in some way, you want to translate the position from screen pixel position to world coordinates.
auto mouse_pos = sf::Mouse::getPosition(window); // Mouse position relative to the window
auto translated_pos = window.mapPixelToCoords(mouse_pos); // Mouse position translated into world coordinates
if(sprite.getGlobalBounds().contains(translated_pos)) // Rectangle-contains-point check
// Mouse is inside the sprite.