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

Pages: [1]
1
Window / Re: Event KeyReleased repetes itself.
« on: June 07, 2024, 07:38:25 pm »
oh... im feeling so dumb rn.
Thank you!

2
Window / Re: Event KeyReleased repetes itself.
« on: June 07, 2024, 05:34:13 pm »
I want to have a boolean that, when the key is pressed is set to true and when it's released it's set to false. The problem was that for some reason as soon as the boolean was set to true, became false.
Anyway, I used  sf::Keyboard::A instead of the integer and now the code works an intended.
Thank you.

3
Window / Event KeyReleased repetes itself.
« on: June 07, 2024, 03:21:39 pm »
Hi, it's the first time i'm trying event handling but the event KeyReleased is not working properly.
The code in question looks like this:
int main() {
        sf::RenderWindow win(sf::VideoMode(800, 800), "Window");
        bool button = false;
        while (win.isOpen()) {
                sf::Event event;
                while (win.pollEvent(event))
                {
                        switch (event.type) {
                        case sf::Event::Closed:
                                win.close();
                                break;
                        case sf::Event::KeyPressed:
                                switch (event.key.code) {
                                case 0:
                                        button = true;
                                        break;
                                }
                        case sf::Event::KeyReleased:
                                switch (event.key.code) {
                                case 0:
                                        button = false;
                                        break;
                                }
                        }
                }
                if (button) {
                        std::cout << "Key pressed" << std::endl;
                }
                else {
                        std::cout << "Key not pressed" << std::endl;
                }

        }
}

I'm trying to manage key imputs as explaned in the event tutorial but as key released keeps repeting the boolean continuously returns false.
Does anyone knows how to fix it?

Pages: [1]
anything