0

这是我的代码

            TouchCollection touch = TouchPanel.GetState();
            if (touch.Count >= 1)
            {
                TouchLocation prevLocation;
                bool prevAvailable = touch[0].TryGetPreviousLocation(out prevLocation);
                System.Diagnostics.Debug.WriteLine("x:"+touch[0].Position.ToString()+"prev"+prevLocation.Position.ToString());

            } 

但在输出窗口中我得到了“x:infinity,y:infinity”。这不是一个真实的立场。任何想法请谢谢:D

4

1 回答 1

0

尝试了您的代码,但我没有在输出“x:infinity, y:infinity”中看到。If prevAvailableis false (and its false when touch.State == Pressed)prevLocation由默认值 Vector2(0,0) 初始化。如果prevAvailable为真(它是 when touch.State == Moved),那么它会获得最后一次触摸位置并且工作得很好。所以这段代码没有问题。输出样本

x:{X:216 Y:363}prev{X:0 Y:0} //state == pressed
x:{X:225 Y:347}prev{X:216 Y:363}
x:{X:244 Y:321}prev{X:225 Y:347}
x:{X:272 Y:293}prev{X:244 Y:321}
x:{X:272 Y:293}prev{X:272 Y:293}
x:{X:443 Y:210}prev{X:0 Y:0} //state == pressed
x:{X:443 Y:210}prev{X:443 Y:210}
x:{X:453 Y:195}prev{X:443 Y:210}
x:{X:471 Y:176}prev{X:453 Y:195}
x:{X:506 Y:145}prev{X:471 Y:176}
x:{X:506 Y:145}prev{X:506 Y:145}
于 2013-10-31T11:34:34.573 回答