使用SFML 1.6,计算按钮按下的最佳方法是什么?

时间:2011-10-23 01:38:26

标签: loops count keypress sfml

例如:

int count;

//Code to count key presses here

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

我已经知道如何将int转换为字符串并插入它。

1 个答案:

答案 0 :(得分:1)

使用事件:

#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;
}