Sign in to follow this  
menyo

Screen management problem

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
Load 0> does nothing yet
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...

[code]
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;
}
[/code]

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
[quote name='j-locke' timestamp='1302587154' post='4797390']
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.


[/quote]

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 this post


Link to post
Share on other sites
[quote name='menyo' timestamp='1302554769' post='4797262']
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?
[/quote]

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"][size="2"]
[code]
// snipped
if(activeScreen == startScreen)
{
if (CheckKey(Keys.Enter)
{
if (startScreen.SelectedIndex == 0) //add conditional breakpoint to this line, breaking if wantToBreak == true.
// snipped
}
}
[/code][/size][/font]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this