Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED]Gamestate changes because KeyPressed reacts to mouse movement  (Read 1545 times)

0 Members and 2 Guests are viewing this topic.

Kleath

  • Newbie
  • *
  • Posts: 7
    • View Profile
Hello, i have a little Problem. I'm programming a little Pong Game. For this I'm using two Gamestates, the MainMenu and the Playstate. Now if I am at the Playstate, i want the ESCPAE Button to go back to the MainMenu.
Now if I'm in the Playstate and move the mouse to the left side of the window, it also goes back to the MainMenu.

With this code :

 if (event.type = sf::Event::KeyPressed)
      {
         if (event.key.code == sf::Keyboard::Escape)
         {
            game.ChangeState(Game::gameStates::MAINMENU);
         }
      }

I'm checking if ESCAPE was pressed. Now if I dont use this code, it doesnt move back to the MainMenu if i move the mouse to the left of the window.

Do you have any ideas what I'm doing wrong?
« Last Edit: April 28, 2016, 04:49:16 pm by Kleath »

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Gamestate changes because KeyPressed reacts to mouse movement
« Reply #1 on: April 28, 2016, 03:57:14 pm »
Hi,
it's because you event.type = ... instead of event.type == ...

Kleath

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Gamestate changes because KeyPressed reacts to mouse movement
« Reply #2 on: April 28, 2016, 04:29:58 pm »
Yeah, thank you. I hate it when this happens xD

 

anything