Actually it was
literally the very first result, that's why I got a bit ticked off.
Maybe my Google settings are different... >_>
The first result for me is this:
http://en.sfml-dev.org/forums/index.php?topic=5662.0And what you get from it is this:
bool isSpriteClicked ( sf::Sprite *spr, sf::RenderWindow *render )
{
const sf::Input& Input = render->GetInput();
if( Input.GetMouseX() > spr->GetPosition().x
&& Input.GetMouseX() < spr->GetPosition().x + spr->GetSize().x
&& Input.GetMouseY() > spr->GetPosition().y && Input.GetMouseY() < spr->GetPosition().y + spr->GetSize().y
&& Input.IsMouseButtonDown(sf::Mouse::Left)
)
{
return true;
}
else
{
return false;
}
}
Usage:
if(isSpriteClicked( &YOUR_SPRITE, &Window ))
{
// Example:
Window.Close();
}
It should work correctly with SFML 1.6 and VS 2008/2010
I helped you. But i see that you dont have any idea on game prgramming . At first you must know C++ better and Do some console games (CLI). Text based. Dont try make 2d/3d games right now! Learn at first!
As Nexus mentioned, this topic was grinded over many times before, there is no point in doing it once more, just because someone is too lazy to spend around 10 seconds to search for the old topic.
BTW, synok the last few sentence in the quote above apply to you too.
Do some tutorials or read some books on game development, before you start programming.
if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
...
}
He should learn to do it without all this fancy stuff, otherwise it is useless.
I mean AABB collisions are one of the very first things you learn, seriously =_="
Hehe, let's make it even shorter
:
if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
if (sprite.getGlobalBounds().contains(window.mapPixelToCoords(sf::Mouse::getPosition(window))))
{
// mouse is on sprite!
}
}