I've tried to do a Button with SFML, but when i click on the Sprite, the program print : "You didn't press the Button"..
Window.cpp :
while(m_window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::MouseButtonPressed:
std::cout << "MouseButtonPressed !" << std::endl;
if(buttonEnter.eventMouse(m_window.mapPixelToCoords(
{event.mouseButton.x, event.mouseButton.y})))
{
std::cout << "You did press the Button " << std::endl;
}
else
{
std::cout << "You didn't press the Button" << std::endl;
}
break;
case sf::Event::Closed:
m_window.close();
default:
break;
}
}
And Button.cpp (buttonEnter)
bool Button::eventMouse(sf::Vector2f const &cursor_position)
{
std::cout << "eventMouse" << std::endl;
bool test = m_spriteButton.getGlobalBounds().contains(
cursor_position.x,cursor_position.y);
return test;
}
The program print (when i click on the Sprite) : MouseButtonPressed ! eventMouse You didn't press the button
{ I think that my code (Windows.cpp and Button.cpp) is good, so this is all my code : https://github.com/Moongm/LoadComponent }
Thank's for you help !