Greetings, fellows I have a bit of a problem here.
Today I decided to get serious with my 2D programming so I started with menu display and have one bug. You see, for now I have 3 buttons, as images which are moving when player press UP or DOWN.But the problem is only first and the last are moving, the one in the middle isnt moving at all or he is moving but too fast for my eyes. Could you tell me how to slow them down? Tried on many things but neither one is helping..
code:
#include <SFML/Graphics.hpp>
#include <sstream>
#include <string>
int meni = 1;
sf::Texture startT;
sf::Texture optionsT;
sf::Texture exitT;
sf::Sprite startS;
sf::Sprite optionsS;
sf::Sprite exitS;
main ()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Pocetak!");
// pozadina
sf::Texture pozadinaT;
pozadinaT.loadFromFile("background.png");
sf::Sprite pozadinaS;
pozadinaS.setTexture(pozadinaT);
// buttons
startT.loadFromFile("StartButton.png");
optionsT.loadFromFile("OptionsButton.png");
exitT.loadFromFile("ExitButton.png");
startS.setTexture(startT);
optionsS.setTexture(optionsT);
exitS.setTexture(exitT);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
if(meni == 1)
{
startS.setPosition(350, 300);
optionsS.setPosition(300, 350);
exitS.setPosition(300, 400);
}
else if(meni == 2)
{
startS.setPosition(300, 300);
optionsS.setPosition(350, 350);
exitS.setPosition(300, 400);
}
else if(meni == 3)
{
startS.setPosition(300, 300);
optionsS.setPosition(300, 350);
exitS.setPosition(350, 400);
}
if(meni < 1)
meni = 1;
if(meni > 3)
meni = 3;
meni++;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
if(meni == 1)
{
startS.setPosition(350, 300);
optionsS.setPosition(300, 350);
exitS.setPosition(300, 400);
}
else if(meni == 2)
{
startS.setPosition(300, 300);
optionsS.setPosition(350, 350);
exitS.setPosition(300, 400);
}
else if(meni == 3)
{
startS.setPosition(300, 300);
optionsS.setPosition(300, 350);
exitS.setPosition(350, 400);
}
if(meni < 1)
meni = 1;
if(meni > 3)
meni = 3;
meni--;
}
window.clear();
window.draw(pozadinaS);
window.draw(startS);
window.draw(optionsS);
window.draw(exitS);
window.display();
}
}
Regards