TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Francisco Dias
NA
3
3.5k
Game State Machine good practices ?! Textbox focus problem.
Oct 30 2013 11:38 PM
I'm creating a Game using WPF (a text based game nothing too heavy).
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).
If I try to Focus TextBox with the help of the
OnLoad
event raised by the UserControl, the TextBox gets focus as expected but the "G" key used to trigger the transition is captured and appears written on the text box... and I don't seem to be able to clear it:
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
Reply
Answers (
0
)
NotifyIcon Balloon problem!
WPF inbuilt form