Page 1 of 1

Check gamestate

Posted: Fri Sep 16, 2016 2:44 am
by jinxtengu
Hey, i just have a simple question, how would you write a condition to check the current gamestate.

would it be like?

return app.gamestate==levelone ;

Sorry is this seems really ignorant. Currently I've been assigning a variable to each gamestate, not a different variable just changing the number for one variable, and returning this number when i need to, but i realized that this probably isn't necessary.
Hope someone can help :)

Re: Check gamestate

Posted: Fri Sep 16, 2016 8:16 am
by Rado1
To implement different states of your game I would recommend to use AppState components - each representing a different state. Then, you probably will not need to check for the game state explicitly, because each AppState can make transition to other states knowing which state is active at the moment of transition. Of course you can have a special variable, e.g. GameState, and set/get its values explicitly:

Code: Select all

// declarations
const int
  TitleScreen = 0,
  LevelIntro = 1,
  Gameplay = 2,
  LevelFinished = 3;

int GameState;

// usage in code
GameState = TitleScreen;
...
if(Gameplay == LevelIntro) ...
but this is usually not necessary if you use AppState components.