Как лучше всего подсчитать нажатия кнопок в SFML 1.6? - PullRequest
0 голосов
/ 23 октября 2011

Например:

int count;

//Code to count key presses here

sf::String String("You have pressed a key this many times: " + count );

Я уже знаю, как преобразовать int в строку и вставить ее.

1 Ответ

1 голос
/ 30 октября 2011

Использовать события:

#include <SFML/Graphics.hpp>
int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
    int count = 0;
    while (window.IsOpened())
    {
        sf::Event event;
        while (window.GetEvent(event))
        {
            if (event.Type == sf::Event::Closed)
                window.Close();
            if (event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Key::A)
                ++count;
        }
        window.Clear();
        // Do whatever you want with count.
        window.Display();
    }
    return 0;
}
...