46
Window / How do you make the keyboard just click one time? (SFML 2.0)
« on: November 04, 2012, 12:03:43 pm »
Hello
I have a problem with the keyboard input thing... i just want it to click 1 single time instead of 2 or 3 times when i click a key.
Heres my code... just so you can see what i mean. Also... Does key A count as "left mouse click"?... it looks like it does. (u can copy and paste if you wanna test)
I have a problem with the keyboard input thing... i just want it to click 1 single time instead of 2 or 3 times when i click a key.
Heres my code... just so you can see what i mean. Also... Does key A count as "left mouse click"?... it looks like it does. (u can copy and paste if you wanna test)
#include <SFML/Graphics.hpp>
#include <sstream>
#include <string>
sf::RenderWindow mywindow(sf::VideoMode(800,600,32),"dsda");
sf::Event ev;
int x = 0;
template <typename T>
std::string toString(T arg)
{
std::stringstream ss;
ss << arg;
return ss.str();
}
int main()
{
sf::Text mytext;
mywindow.setVerticalSyncEnabled(true);
while(mywindow.isOpen())
{
mytext.setString(toString(x));
while(mywindow.pollEvent(ev))
{
if(ev.key.code == sf::Keyboard::A)
{
x++;
}
}
mywindow.clear(sf::Color(0,200,0));
mywindow.draw(mytext);
mywindow.display();
}
}
#include <sstream>
#include <string>
sf::RenderWindow mywindow(sf::VideoMode(800,600,32),"dsda");
sf::Event ev;
int x = 0;
template <typename T>
std::string toString(T arg)
{
std::stringstream ss;
ss << arg;
return ss.str();
}
int main()
{
sf::Text mytext;
mywindow.setVerticalSyncEnabled(true);
while(mywindow.isOpen())
{
mytext.setString(toString(x));
while(mywindow.pollEvent(ev))
{
if(ev.key.code == sf::Keyboard::A)
{
x++;
}
}
mywindow.clear(sf::Color(0,200,0));
mywindow.draw(mytext);
mywindow.display();
}
}