Hellow everyone ! :) I have some problems with sfml :'( the thing is that i am checking if mouse is over the sprite and everything seems fine(first time a made this)
bool isMouseOverObjectBox(sf::Sprite &object, sf::Texture &tex, sf::RenderWindow &target){
sf::Vector2i Mpos(sf::Mouse::getPosition(target));
sf::Vector2f pos(object.getPosition());
sf::Vector2u size(tex.getSize());
if(Mpos.y >= pos.y && Mpos.x >= pos.x && Mpos.y <= pos.y+size.y && Mpos.x <= pos.x+size.x){
return true;
}
return false;
}
but this isn't all i want. i want to make it work with rotated, scaled sprite and unfortinatly i don't know how to do it can anyone help me?
I think i found what you need :
http://www.sfml-dev.org/tutorials/2.2/graphics-transform.php
In the bouding box section there is this :
// get the bounding box of the entity
sf::FloatRect boundingBox = entity.getGlobalBounds();
// check collision with a point
sf::Vector2f point = ...;
if (boundingBox.contains(point))
{
// collision!
}
Make the "point" contain your mouse coordinates and i will work ( i think :) )