SFML community forums

Help => General => Topic started by: Battleapple on January 04, 2014, 04:57:12 pm

Title: Using switch to change what is displayed on screen does not work
Post by: Battleapple on January 04, 2014, 04:57:12 pm
To switch between a splash,a title and a menu screen i wanted to use switch with an integer.If the space key would have been pressed,the int value would be increased:

int Screen;
while (window.isOpen())
   {
      Event event;
      while (window.pollEvent(event))
      {
         if (event.type == Event::Closed){ window.close(); }
      }
                if(Keyboard::isKeyPressed(Keyboard::Space)){Screen+1;}
      window.clear();
      switch (Screen)
      {
      case 0:
         window.draw(Sp_Splash);
         break;
      case 1:
         window.draw(Sp_Title);
         break;
      default:
         break;
      }
      window.display();
   }

But when i press space nothing happens(the Screen does not change).
Does anyone know why?
Title: Re: Using switch to change what is displayed on screen does not work
Post by: Daddi on January 04, 2014, 05:00:28 pm
You should start learning basic C++ :)

1. Your keyboard checks have to be inside the while statement.
2. Screen + 1 does nothing. Either do ++Screen; or Screen = Screen + 1;
3. Learn C++ before you start using SFML :D
Title: Re: Using switch to change what is displayed on screen does not work
Post by: Battleapple on January 04, 2014, 05:40:37 pm
Thank you for the first answer.To get to your other statements:
I only could use an older version of my code (since i dont have my main pc next to me right now).So i forgot to fix that +1.But honestly dont be so condenscending because i made one simple mistake.
Title: Re: Using switch to change what is displayed on screen does not work
Post by: Daddi on January 04, 2014, 07:10:42 pm
You're right, I'm sorry. I jumped to conclusions to fast :)