我想你可以尝试使用TouchPanel从XNA - 它工作得很好,我想会做你想要什么:
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework;
public MainPage()
{
InitializeComponent();
TouchPanel.EnabledGestures = GestureType.Tap;
this.Tap += MainPage_Tap;
}
private void MainPage_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
GestureSample gesture = TouchPanel.ReadGesture();
Vector2 vector = gesture.Position;
int positionX = (int)vector.X;
int positionY = (int)vector.Y;
}
左上角为(0,0)和无论您的应用具有何种方向,您都会获得相对的位置。
编辑 - 几句话
请注意,您也可以在CompositionTarget.Rendering或定时检查TOUCHINPUT - 这取决于你想要达到的目标。
还要注意,当你使用XNA你可能有时候需要做的:
FrameworkDispatcher.Update();
EDIT 2 - 捏例如
如果你想使用捏或其它手势也可以是这样的:
public MainPage()
{
InitializeComponent();
TouchPanel.EnabledGestures = GestureType.Pinch;
this.ManipulationCompleted+=MainPage_ManipulationCompleted;
}
private void MainPage_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
if (TouchPanel.IsGestureAvailable)
{
GestureSample gesture = TouchPanel.ReadGesture();
Vector2 vector = gesture.Position;
int positionX = (int)vector.X;
int positionY = (int)vector.Y;
// do what you want with your positin
// there are also some more properties in which you may be interested
// also TouchPanel has properites like TouchPanel.DisplayWidth and DisplayHeight if you need them
}
}
对于FrameworkDispatcher.Update() - 我认为你可以叫它OnNavigetedTo()。
看起来很有趣,我会试着看看明天。并回报。 – JTIM
我试过你的代码,看起来像它做我想要的。但这不是我需要的事件。我希望它为捏事件。然而,我一直无法做到这一点,你能帮我把它转换为使用捏来代替吗?还FrameworkDispatcher.Update,应该何时调用? – JTIM
@JTIM我在编辑2中添加了,你问了什么。另请参阅其他手势类型,也许您会对它们感兴趣。我也添加捏到ManipulationCompleted - 请注意,它可以是ManipalationStarted,或delta,如果你需要它们。 – Romasz