Windows Phone/XNA 检测触摸开始

本文关键字:触摸 开始 检测 XNA Phone Windows | 更新日期: 2023-09-27 18:33:11

我想让按钮在Windows Phone中触摸时改变颜色,但唯一可用的手势是GestureType.Tap点击完成后调用的手势,因此在用户触摸按钮后颜色会发生变化。如何使触摸在被触摸后立即检测到?

        while (TouchPanel.IsGestureAvailable)
        {
            GestureSample gs = TouchPanel.ReadGesture();
            switch (gs.GestureType)
            {
               //this is called AFTER the tap
               case GestureType.Tap:
                    if (Restart.tapped(gs.Position))
                        Restart.selectDrawColor = Color.OrangeRed;
                    else
                        Restart.selectDrawColor = Color.White;
                    if (uploadScore.tapped(gs.Position))
                        uploadScore.selectDrawColor = Color.OrangeRed;
                    else
                        uploadScore.selectDrawColor = Color.White;
                    if (MainMenu.tapped(gs.Position))
                        MainMenu.selectDrawColor = Color.OrangeRed;
                    else
                        MainMenu.selectDrawColor = Color.White;
                    break;
            }
        }

Windows Phone/XNA 检测触摸开始

触摸

屏幕不被视为手势,因此ReadGesture不会返回它。您将需要调用 TouchPanel.GetState() 并查找StatePressed 的任何TouchLocation对象。

// using System.Linq;
TouchLocation[] newTouchLocations = TouchPanel.GetState()
    .Where(loc => loc.State == TouchLocationState.Pressed)
    .ToList();

根据文档,TouchLocationState.Pressed表示:

此触摸位置是新的。