Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Plavsa

Pages: [1]
1
General / Re: Menu problem
« on: July 22, 2013, 09:35:24 pm »
It is indeed moving too fast.

You call if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) (and Up) one time per frame. And there are a few hundreds/thousands frame every second, so meni's value is 2 only for one or a few milliseconds.

Maybe events (sf::Event::KeyPressed or Released) are more relevant for your case than real-time inputs.

Thanks, it works. :)

2
General / Menu problem[solved]
« on: July 22, 2013, 06:30:31 pm »
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

Pages: [1]
anything