I'm trying to make it so the character moves a set distance when a key is pressed, but it keeps sliding even though i used window.setKeyRepeatEnabled(false)
(I'm using version 2.6)
code:
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Window");
window.setKeyRepeatEnabled(false);
sf::Sprite sprite;
sf::Texture texture;
if (!texture.loadFromFile("Awsome.png", sf::IntRect(10, 10, 320, 320)))
{
printf("failed to load");
}
sprite.setTextureRect(sf::IntRect(170, 100, 100, 100));
sprite.setColor(sf::Color(255, 255, 2, 255));
sprite.setTexture(texture);
window.setVerticalSyncEnabled(true);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Left) {
sprite.move(-30.f, 0.f);
}
if (event.key.code == sf::Keyboard::Right) {
sprite.move(30.f, 0.f);
}
}
window.clear(sf::Color::Black);
window.draw(sprite);
window.display();
}
return 0;
}