XNA 独有的可锁定输入处理
我正在编写一个 XNA 应用程序,它需要将输入仅定向到一个输入事件处理程序,该处理程序是当前锁定的对象,即游戏、菜单、控制台等。
执行此操作的最佳方法是什么?我考虑过创建一个 IInputReceiver 接口(使用诸如 HandleInput 之类的方法),该接口附加到中央输入管理器,该管理器仅将输入事件发送到锁定的输入接收器。
只是想知道其他人如何处理输入处理。
I'm writing an XNA application which requires input directed to only one input event handler, which is the object that is currently locked, i.e. game, menu, console, etc.
What is the best way to do this? I've thought about creating an IInputReceiver
interface (with methods such as HandleInput
) that attaches into a central input manager which only sends input events to the locked input receiver.
Just wondering about what other people do with input handling.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法 - 以及 XNA 本身处理事物的方法 - 是将输入设为全局(使用静态类)。在游戏/菜单/控制台的
更新
函数中,只需查询输入状态即可。您可能不应该同时对多个对象调用
Update
。如果出于某种原因必须这样做,我建议在每个读取输入状态的函数上使用单独的InputUpdate
函数。如果你需要“按键上/下”处理 - 在 XNA 中通常是通过存储最后一个状态和当前状态来完成 - 我发现全局存储这些也是最简单的,并在开始时“泵送”它您的 Game.Update 函数。
这听起来可能不是特别花哨——但这是游戏的输入。它不必很花哨!
我不太明白你所说的“可锁定”是什么意思 - 但我觉得我应该指出 XNA 输入(读取)必须在主线程上完成。
The easiest way - and the way that XNA itself handles things - is making input global (using static classes). In your
Update
function for your Game/Menu/Console, simply query the input state.You probably shouldn't be calling
Update
on more than one of these objects at the same time. If you have to, for some reason, I recommend having a separateInputUpdate
function on each that reads the input state.If you need "key-went-up/down" handling - which in XNA is generally done by storing the last state and the current state - I find it is also easiest to store these globally, and "pump" it at the start of your
Game.Update
function.This may not sound particularly fancy - but this is input for a game. It doesn't have to be fancy!
I don't really understand what you mean by "lockable" - but I feel I should point out that XNA input (reads) must be done on the main thread.