Hi... I know this question has been posted loads of times. I tried out all those solutions, but none of them are giving me desired output. I want to click on a sprite which will trigger an action, but it is not working for some reason. I tried two alternatives,
Mouse Click event in the event loop:
while(window.pollEvent(event))
{
if(event.key.code == sf::Keyboard::Escape)
window.close();
if(event.type == sf::Event::Closed)
window.close();
if(event.mouseButton.button == sf::Mouse::Left)
{
if(event.mouseButton.x > ebound.left && event.mouseButton.x < (ebound.left + ebound.width) && event.mouseButton.y > ebound.top && event.mouseButton.y < (ebound.top + ebound.height))
window.close();
}
}
Mouse Click in the window loop:
float mouseX = (float)sf::Mouse::getPosition().x;
float mouseY = (float)sf::Mouse::getPosition().y;
if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
if(ebound.contains(mouseX, mouseY))
window.close();
What is wrong? Why is it not working? Please tell me. Thank you.