I'm trying to handle the game states: TitleScreen, PlayScreen, PauseScreen... using a ScreenManager - a static class that adds a given screen to a list (stack) and places the most uptop screen in a MainWindow container (to be displayed).
The input is handled in a way I don't know if it is tottaly right:
TitleScreen inherits from Screen which inherits from UserControl - Screen is an abstract class that implements some methods and stores a MainWindow reference this way each Screen can register to the MainWindow KeyDown (event) and add it's input logic.
TitleScreen : [Key.A] goes to PlayScreen, [Key.Escape] exists
PlayScreen: [Key.B] goes to PauseScreen, [Key.Space] exists
...
My first question is: Is this the right way to go?! Everything till here works, but I wanted to know if there is a better way to handle input (this one seams a little odd). Or another way to handle the "state machine".
Now the text box problem... as I transit from TitleScreen to PlayScreen there is a textbox in PlayScreen used for inputing commands (I want it to be focus right from the beginning).
- As the G key is pressed during TitleScreen
- I instanciate the PlayScreen UserControl
- Remove the previous Screen (title)
- Place the new screen in the MainWindow container
- Set the focus to the text box.
- ERROR: Textbox has caret but caret is not blinking (Keyboard.Focus() doesn't seem to work either).
TextBox.Text = string.empty;
TextBox.Clear();
Don't work... I'm doing this for a while now I'm becoming desperate.
please help. Thank you
Replies
Know the answer? Post it — somebody with the same question will find it here.