Hi there, I'm having some difficulties trying to detect if the mouse is hovered over and clicking on the sprite. I want it to change sprites once it's hovered over, then change states once it is clicked on. The only thing I'm having trouble on is the mouse. Here's my code that compiles but doesn't seem to work:
void IntroState::update() {
sf::Event event;
while(m_game.screen.pollEvent(event)) {
switch(event.type) {
case sf::Event::Closed:
m_game.quit();
break;
case sf::Event::KeyPressed:
switch (event.key.code)
{
case sf::Keyboard::Escape:
m_game.quit();
break;
}
break;
break;
case sf::Event::MouseButtonPressed:
if (s_playButton.getGlobalBounds().contains(sf::Mouse::getPosition().x, sf::Mouse::getPosition().y))
{
m_game.screen.draw(s_playButtonActive); //replace current button with a highlighted one since it is being hovered over
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) // if the playbutton is being hovered over AND the left mouse button is being clicked
{
//do stuff
}
}
break;
}
}
}
I appreciate any help. Thanks!