Hello, I'm writing a small 2D mini-game in which I'm developing a menu. I wrote events to be checked when the mouse is over a button so that specific actions can be triggered but for some reason the mouse event doesn't seem to get triggered at all. When I click over a button nothing happens and I've been checking my code and referencing Google and different tutorials as well as these forums for hours but I can't seem to figure out the problem. I'm using SFML 2.0 and visual studio 11. Any help is much appreciated, thanks.
Here is my code:
int nCurrentScene=1;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
//Buttons
sf::Vector2i localPosition = sf::Mouse::getPosition(window);
sf::FloatRect sStartBnRec = sStartBn.getGlobalBounds();
sf::FloatRect sExitBnRec = sExitBn.getGlobalBounds();
sf::Event eMouseClk;
if(sStartBnRec.contains(localPosition.x,localPosition.y))
{
sStartBn.setTexture(tStartBn_hl);
while(window.pollEvent(eMouseClk))
{
if (eMouseClk.type == sf::Event::MouseButtonPressed)
{
if(eMouseClk.mouseButton.button == sf::Mouse::Left)
{
nCurrentScene=2;
}
}
}
}
else
{
sStartBn.setTexture(tStartBn);
}
if(sExitBnRec.contains(localPosition.x,localPosition.y))
{
sExitBn.setTexture(tExitBn_hl);
while(window.pollEvent(eMouseClk))
{
if (eMouseClk.type == sf::Event::MouseButtonPressed)
{
if(eMouseClk.mouseButton.button == sf::Mouse::Left)
{
EXIT_SUCCESS;
}
}
}
}
else
{
sExitBn.setTexture(tExitBn);
}
window.clear();
switch (nCurrentScene)
{
case 1:
window.draw(sMenuBg);
window.draw(sExitBn);
window.draw(sStartBn);
break;
case 2:
window.draw(sLvloneBg);
break;
}
window.display();
}
return 0;
}