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 - grhomb

Pages: [1]
1
Window / Re: Key repeats still occur even when set to false
« on: December 31, 2024, 03:14:57 pm »
Thanks, somehow I just didn't see which curly brace corresponded to the loop before

2
Window / Key repeats still occur even when set to false
« on: December 31, 2024, 12:14:15 am »
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;
}

Pages: [1]
anything