Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

What's the best way to handle game states / screens? My problem is this:

PlayGameScreen adds a new InventoryGameScreen to the game during it's update. This immediately adds InventoryGameScreen to the array of GameScreens. That's throwing an exception when iterating over the array that the contents of the array have changed.

Should I have two more arrays, like screensToBeAdded and screensToBeRemoved and do all the processing for them at the end of the game loop after drawing all the other screens?

share|improve this question
    
add comment

1 Answer

There are several equally valid approaches, and enqueuing pending changes for later processing like you have suggested is but one of them. It will work just fine; without more details it's hard to provide much more advice.

That said, this concrete example is for game state management in XNA, but the concepts should apply to any language/platform/technology/et cetera and it might help demostrate a working solution you can learn from.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.