Troubleshooting this TutorialSometimes, even though you try hard to understand the information in a tutorial, things don't work out quite like you want it to. This page is here to help you resolve any problems you might be having with basic keyboard input. The Common Mistakes section describes common problems that people have when doing the things in this tutorial, and how to resolve them. The Frequently Asked Questions section describes questions that people have that aren't related to mistakes, but rather, trying to understand the stuff better or exploring how it can be used. If your problem or concern isn't addressed here, feel free to add a comment below, so that I know where you're having trouble. I like to keep these pages fairly clean, so I may remove comments that I felt like have been addressed. If I remove your comment and you don't feel like the problem has been fixed, repost the question and we'll take another look at it. If a tutorial has a mistake in it, I will fix the mistake and reply to the comment with a brief explanation. However, after a couple of weeks I'll likely go back and remove the original comment as well as my reply, because, hopefully, the problem will have been fixed, and it won't be a concern any more. |
Common MistakesNone listed yet… |
Frequently Asked QuestionsNone listed yet… |
Hi, when I enter the IsKeyPressed, XNA returns an error saying that Microsoft.XNA.Framework.Input.KeyboardState doesnt contain a definition for it and no extension method could be found, could you point out where Iv went wrong with this? Thanks
I just realised I wrote Pressed instead of Down! Sorry!
It is yelling at me over the line KeyboardState state = Keyboard.GetState(), telling me "The type of namespace name 'GetState' does not exist in the namespace 'Keyboard' (are you missing an assembly reference?)"
I had stupidly named my project 'Keyboard' so it wasn't finding the reference. My bad.
Glad you got it working. I was going to suggest that.
Technically, it's not the project name that is causing problems, but the namespace name. By default, the namespace at the root level is the same name as project, so there you go.
If you're curious about how to change just the namespace name, without changing the project name, let me know and I'll give you some more details about that.
i love your blog and i think its going to my favorite!!i love viagra and cialis too! bacdafbacaddddba
Hi!
We start an monogame application using another thread as followed:
viThread = new Thread(startDemo);
viThread.Priority = ThreadPriority.Highest;
viThread.Start();
And inside startDemo:
using (Demo d = new Demo())
d.Run();
This works fine, and I press 'Esc' and it goes to Exit.Game(). Then I try start the monogame application again but this time it's only react on Touch/Mouse inputs, Keyboard.GetState() is always empty. My feeling is that i dont Dispose the objects/reference I need when I quit the application the first time sine the memory is increased as well.
That's an interesting way to do things.
You're restarting it in the same process the second time?
My gut feel is that it might actually be the opposite. Rather than not disposing something, you might be over-disposing something. The game will get disposed when it leaves the using block. I'm not sure what else it disposes in the process. Definitely some stuff. It assumes all of its dependencies are dead too, because the game is exiting. (I'm assuming you mean Game.Exit(), rather than Exit.Game(), right?)
When you try to restart the game the second time around, some of those things have been disposed. Perhaps something inside of the static Keyboard class. Though honestly, I don't know why mouse would be any different. (Mouse.GetState() works, right?)
What are you trying to accomplish with this? Would starting a new process, rather than a new thread, fix your problem? Launching a game is probably more often done in a new process, not in the same one as the launcher. Don't know if that helps much, but it's about as much as I can tell for now.
Post preview:
Close preview