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

Pages: [1]
1
General / Switch case behaving weirdly
« on: September 24, 2023, 12:20:15 am »
I have this peice of code:

**BEGIN CODE HERE**

#include "SFML/Graphics.hpp"
#include <iostream>
int main()
{
        sf::RenderWindow window(sf::VideoMode(600, 600), "My window");
        sf::Event myEvent;

        while (window.isOpen())
        {
                while (window.pollEvent(myEvent))
                {
                        switch (myEvent.type)
                        {
                        case sf::Event::TextEntered:
                                std::cout << static_cast<char>(myEvent.text.unicode);
                                std::cout << "pollEventBroken";
                                break;
                        case sf::Event::KeyPressed:
                                if (myEvent.key.code == sf::Keyboard::E)
                                {
                                        std::cout << &#39;\n&#39;;
                                        break;

                                }
                        }
                }
        }
}
**END CODE HERE**

my question is why is it that when I press the key "e", the first and the second cases run instead of only the first one being run and the loop being broken?

Pages: [1]