XNA - 键盘输入
我今天刚刚开始使用 XNA Framework 4.0,我想知道从键盘获取输入的最简单方法是什么。我认识 C# 中的很多 C++,但它的整个 Java 方面对我来说很陌生。这与 XNA 结合起来有点令人困惑,所以请具体说明并给出示例。谢谢。
I just started using XNA Framework 4.0 today, and I was wondering what the easiest way was to get input from the keyboard. I recognize a lot of C++ in C# but the whole Java side of it is alien to me. This coupled with XNA is a little confusing so, please be specific and give examples. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您习惯在 VS 中使用对象浏览器,我建议您查看 Microsoft.Xna.Framework.Input.Keyboard/Keyboardstate。这些条目将向您展示您可以使用的现成功能。或者,您可以查看 MSDN 或按照 Creator's Club 上的教程进行操作。我将发布一个快速片段来检查特定的击键。
theKey 是在此代码段范围之外定义的参数。您可以将 theKey 设置为一个特定值,您希望在按下该值时触发某些特定的程序行为(在上面片段中的注释位置)。 theKey 定义为:
previousState 和 currentState 定义为:
虽然可能不是最漂亮的方法,但它有效,并且是一个相当简单的构建示例。希望有帮助。
If you're comfortable mucking around with the Object Browser in VS, I'd advise looking at Microsoft.Xna.Framework.Input.Keyboard/Keyboardstate. These entries will show you what you have available to you in terms of ready-made functions. Alternatively, you could look on MSDN or follow a tutorial on Creator's Club. I'll post a quick snippet that checks for a specific keystroke.
theKey is a parameter that is defined outside of the scope of this snippet. You could set theKey to a specific value that you would want to trigger some specific program behavior on pressing (at the commented location in the fragment above). theKey is defined as:
previousState and currentState are defined as:
While perhaps not the prettiest way of doing that, it works and is a fairly straightforward example to build from. Hope that helps.