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

Author Topic: Using switch to change what is displayed on screen does not work  (Read 1540 times)

0 Members and 2 Guests are viewing this topic.

Battleapple

  • Newbie
  • *
  • Posts: 10
    • View Profile
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?

Daddi

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
    • http://foxdev.de/
    • Email
Re: Using switch to change what is displayed on screen does not work
« Reply #1 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

Battleapple

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Using switch to change what is displayed on screen does not work
« Reply #2 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.

Daddi

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
    • http://foxdev.de/
    • Email
Re: Using switch to change what is displayed on screen does not work
« Reply #3 on: January 04, 2014, 07:10:42 pm »
You're right, I'm sorry. I jumped to conclusions to fast :)


 

anything