简体   繁体   English

我应该如何阅读在WPF中创建2D游戏的键盘输入?

[英]How should I go about reading keyboard inputs for creating a 2D game in WPF?

I'm trying to create a 2D game in C# using as a WPF application. 我正在尝试使用WPF应用程序在C#中创建2D游戏。 My XAML is simply just a Grid with an Image in which is drawn to in a CompositionTarget.Rendering method. 我的XAML只是一个带有ImageGrid ,在CompositionTarget.Rendering方法中将其绘制到其中。 How should I got about setting up code to read keystrokes that will be used to move sprites? 我应该如何设置代码以读取将用于移动精灵的击键?

As a side objective I'd also like to read a gamepad's input too for the program so I want something that won't cause problems for controller support later on. 作为辅助目标,我也想阅读该程序的游戏手柄输入,因此我希望以后不会对控制器支持造成问题。

You can use this in your wpf window: 您可以在wpf窗口中使用它:

<Window>
   <Window.InputBindings>
      <KeyBinding Key="Left" Command="{Binding DoSomethingMoveLeftOrSo}"/>
   </Window.InputBindings>
</Window>

And in the command you can perform your action 在命令中您可以执行操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM