[英]Hey i try to build a game in UWP(c#) and i cant make my player move
i search in the internt and only found WPF tutorials to how make objects move and it is diffrent from UWP.我在互联网上搜索,只找到了关于如何使对象移动的 WPF 教程,它与 UWP 不同。
e.VirtualKey == Windows.System.VirtualKey.Up) e.VirtualKey == Windows.System.VirtualKey.Up)
tried to do use this with if statment to change position of the object but coudlnt figure it out the keys doesnt work.do you an idea?Thanks尝试使用 if 语句来更改对象的位置,但无法弄清楚键不起作用。你有什么想法吗?谢谢
So you can use the CoreWindow.KeyDown event to handle keys:所以你可以使用 CoreWindow.KeyDown 事件来处理键:
public MainPage()
{
this.InitializeComponent();
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
}
private void CoreWindow_KeyDown(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs args)
{
switch (args.VirtualKey)
{
case Windows.System.VirtualKey.Left:
//Go left
break;
case Windows.System.VirtualKey.Right:
//Go right
break;
case Windows.System.VirtualKey.Up:
//Go up
break;
case Windows.System.VirtualKey.Down:
//Go down
break;
}
//In case you want to check for Control + Key:
var ctrl = Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Control);
if (ctrl.HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down))
{
//Control was pressed
if (args.VirtualKey == Windows.System.VirtualKey.W)
{
//Do sprint
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.