1
Graphics / Clickable Sprite
« on: September 30, 2015, 12:59:55 am »
Hey Guys,
im just starting out and im having a little bit of trouble.
Im making a Pong clone but im already failing at the Menu .
The problem is that if i want to exit/play the game i have to click several times while moving the mouse(if i dont move the mouse it wont react) but i want to one-click without movement to start/exit the game.
im using SFML 2.1 and visual studio.
thanks in advance
im just starting out and im having a little bit of trouble.
Im making a Pong clone but im already failing at the Menu .
The problem is that if i want to exit/play the game i have to click several times while moving the mouse(if i dont move the mouse it wont react) but i want to one-click without movement to start/exit the game.
Menu::menuState Menu::showMenu(sf::RenderWindow &window)
{
sf::Texture pong;
sf::Texture startGame;
sf::Texture exitGame;
pong.loadFromFile("images/pongScreen.png");
startGame.loadFromFile("images/startGame.png");
exitGame.loadFromFile("images/exitGame.png");
sf::Sprite s_pong(pong);
sf::Sprite s_startGame(startGame);
sf::Sprite s_exitGame(exitGame);
s_pong.setPosition(200, 60);
s_startGame.setPosition(280, 225);
s_exitGame.setPosition(280, 275);
window.draw(s_pong);
window.draw(s_startGame);
window.draw(s_exitGame);
window.display();
sf::Event currentEvent;
while (window.pollEvent(currentEvent))
{
if (currentEvent.type == sf::Event::MouseButtonPressed)
{
if (currentEvent.mouseButton.button == sf::Mouse::Left)
{
if (sf::Mouse::getPosition(window).y > s_startGame.getGlobalBounds().top &&
sf::Mouse::getPosition(window).y < s_startGame.getGlobalBounds().height + s_startGame.getGlobalBounds().top &&
sf::Mouse::getPosition(window).x < s_startGame.getGlobalBounds().width + s_startGame.getGlobalBounds().left &&
sf::Mouse::getPosition(window).x > s_startGame.getGlobalBounds().left)
{
return playing;
}
if (sf::Mouse::getPosition(window).y > s_exitGame.getGlobalBounds().top &&
sf::Mouse::getPosition(window).y < s_exitGame.getGlobalBounds().height + s_exitGame.getGlobalBounds().top &&
sf::Mouse::getPosition(window).x < s_exitGame.getGlobalBounds().width + s_exitGame.getGlobalBounds().left &&
sf::Mouse::getPosition(window).x > s_exitGame.getGlobalBounds().left)
{
return exiting;
}
}
}
}
return wait;
}
{
sf::Texture pong;
sf::Texture startGame;
sf::Texture exitGame;
pong.loadFromFile("images/pongScreen.png");
startGame.loadFromFile("images/startGame.png");
exitGame.loadFromFile("images/exitGame.png");
sf::Sprite s_pong(pong);
sf::Sprite s_startGame(startGame);
sf::Sprite s_exitGame(exitGame);
s_pong.setPosition(200, 60);
s_startGame.setPosition(280, 225);
s_exitGame.setPosition(280, 275);
window.draw(s_pong);
window.draw(s_startGame);
window.draw(s_exitGame);
window.display();
sf::Event currentEvent;
while (window.pollEvent(currentEvent))
{
if (currentEvent.type == sf::Event::MouseButtonPressed)
{
if (currentEvent.mouseButton.button == sf::Mouse::Left)
{
if (sf::Mouse::getPosition(window).y > s_startGame.getGlobalBounds().top &&
sf::Mouse::getPosition(window).y < s_startGame.getGlobalBounds().height + s_startGame.getGlobalBounds().top &&
sf::Mouse::getPosition(window).x < s_startGame.getGlobalBounds().width + s_startGame.getGlobalBounds().left &&
sf::Mouse::getPosition(window).x > s_startGame.getGlobalBounds().left)
{
return playing;
}
if (sf::Mouse::getPosition(window).y > s_exitGame.getGlobalBounds().top &&
sf::Mouse::getPosition(window).y < s_exitGame.getGlobalBounds().height + s_exitGame.getGlobalBounds().top &&
sf::Mouse::getPosition(window).x < s_exitGame.getGlobalBounds().width + s_exitGame.getGlobalBounds().left &&
sf::Mouse::getPosition(window).x > s_exitGame.getGlobalBounds().left)
{
return exiting;
}
}
}
}
return wait;
}
im using SFML 2.1 and visual studio.
thanks in advance