# Screen management problem

This topic is 2688 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,

I did a tutorial on screen management, although for xna 3.0 / 3.1 i got it to work for 4.0. But when i started adding a menu to it i ran into some problems.

At first the start screen loads with 3 options:
Start -> Goes to character creation
Exit -> Exits game

The charcreationscreen has another 3 options
Reroll -> does nothing yet
Accept -> starts game
Back -> back to start screen

Now when i go to the charcreation screen and then hit back i can't go to the character creation screen anymore, the string for it is showing, i can select it but enter does not do anything. The exit option still works though. Do i need to reset the screen component <list> or something?

Heres the code in game1 update, dunno if you need more code though...

 protected override void Update(GameTime gameTime) { keyboardState = Keyboard.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); if (activeScreen == startScreen) { if (CheckKey(Keys.Enter)) { if (startScreen.SelectedIndex == 0) { activeScreen.Hide(); activeScreen = characterCreationScreen; activeScreen.Show(); } if (startScreen.SelectedIndex == 2) { this.Exit(); } } } if (activeScreen == characterCreationScreen) { if (CheckKey(Keys.Enter)) { if (characterCreationScreen.SelectedIndex == 0) { //reroll character stats } if (characterCreationScreen.SelectedIndex == 1) { activeScreen.Hide(); activeScreen = actionScreen; activeScreen.Show(); } if (characterCreationScreen.SelectedIndex == 2) { activeScreen.Hide(); activeScreen = startScreen; activeScreen.Show(); } } } base.Update(gameTime); oldKeyboardState = keyboardState; } 

##### Share on other sites
Looking over the code, I'm not seeing what would cause you to not be able to go back to characterCreationScreen.

Have you tried setting a breakpoint on activeScreen = characterCreationScreen and making sure it's getting run on your second time in that menu? If it is, maybe step through from there to see what's going on. If it's not, set a breakpoint somewhere else (maybe where you set activeScreen = startScreen) and see what happens on the next iteration through Update.

Edit: Actually, I looked over it once more after my post. I think that breakpoint idea would have gotten you to this same conclusion, but it looks to me like when you're on the main menu the second time, you press enter with characterCreationScreen selected. Then in that SAME FRAME, characterCreationScreen is active and the Enter key is down (because this is still the same frame after all) and SelectedIndex is still 2 I presume, since that's what it was last time you were in this screen. So startScreen gets set back to being the activeScreen before you even get to your draw code.

I'm not saying what's the "right" way to solve the problem as I haven't used that style of screen management, but making that and else if would solve the problem so that only one screen could be processed per update call. So else if (activeScreen == characterCreationScreen)

##### Share on other sites
DOH!!!!
thanks!

I'm pretty new, i have used breakpoints before but.... The problem is, when i use break points i can't use the game anymore, it does not pop up when i start game/debugging and goes unclickable when it's already opened. So no inputting commands anymore so i could not see what happend there in the code, else i would have probably seen it myself. I have looked up some debugging solutions but without succes.

Is there a simple tutorial on how to debug with the game screen active, so i can trace a problem like that?

##### Share on other sites
That is a good point. I don't know any particularly good resources on debugging. I was introduced to it in classes and with class textbooks. And then use of it has developed through actually debugging code.

Maybe someone else will come across the thread and be able to point out a good online resource.

##### Share on other sites

That is a good point. I don't know any particularly good resources on debugging. I was introduced to it in classes and with class textbooks. And then use of it has developed through actually debugging code.

Maybe someone else will come across the thread and be able to point out a good online resource.

Thanks you sir, yes i have seen people using code to debug but since i'm just a beginner i figured it's still to early to get into that. Some infor or a nice tutorial about the basics of debugging in c#/XNA would be really appreciated.

##### Share on other sites

DOH!!!!
thanks!

I'm pretty new, i have used breakpoints before but.... The problem is, when i use break points i can't use the game anymore, it does not pop up when i start game/debugging and goes unclickable when it's already opened. So no inputting commands anymore so i could not see what happend there in the code, else i would have probably seen it myself. I have looked up some debugging solutions but without succes.

Is there a simple tutorial on how to debug with the game screen active, so i can trace a problem like that?

You could try conditional break points. Add a global boolean wantToBreak, initialize it to false, set it to true when you leave charactercreationscreen.
[font="Arial"]
 // snipped if(activeScreen == startScreen) { if (CheckKey(Keys.Enter) { if (startScreen.SelectedIndex == 0) //add conditional breakpoint to this line, breaking if wantToBreak == true. // snipped } } [/font]

1. 1
2. 2
JoeJ
20
3. 3
frob
18
4. 4
5. 5

• 10
• 10
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632200
• Total Posts
3004741

×