计算跳跃动作手势的次数

时间:2014-01-15 02:14:52

标签: wpf

我正在尝试使用c#计算使用跳跃动作和WPF制作手势的次数。我有一个应用程序,每当bug被击中时,它将计算得分。这是我的代码,但计数错了。我做了一些研究,它说,因为它也计算了做手势的过程。请帮忙!有什么建议?如果您知道有任何其他更简单的方法来计算手势的次数,请告诉我吗?


private void ListenerOnOnGestureMade(GestureList gestureList)

    {
        foreach (var gesture in gestureList)

        {
            if (gesture.Type == Gesture.GestureType.TYPECIRCLE || gesture.Type == Gesture.GestureType.TYPESWIPE)

            {
                Dispatcher.Invoke(() =>

                    {
                        SwipeGesture swipeGesture = new SwipeGesture(gesture);
                        var storyboard = (Storyboard)TryFindResource("finger-animation");
                        storyboard.Begin();

                        TryKillBugs(finger, 100, 60);



                    });
            }

     private void TryKillBugs(UIElement image, int width, int height)

    {
        var fingerRect = new Rect

        {
            Location = image.PointToScreen(new Point(180, 0)),
            Height = 200,
            Width = 200
        };

        foreach (var bug in bugs)
        {
            var bugRect = new Rect
            {
                Location = bug.PointToScreen(new Point(180, 0)),
                Height = bug.ActualHeight,
                Width = bug.ActualWidth
            };

            if (fingerRect.IntersectsWith(bugRect))


                bug.Visibility = Visibility.Collapsed;

            _killings++;

        score.Text = (_killings).ToString();




        }
    }

1 个答案:

答案 0 :(得分:0)

计数器增量应该在if内,你的代码实际上是在计算屏幕上的所有错误

if (fingerRect.IntersectsWith(bugRect))
 {
    bug.Visibility = Visibility.Collapsed;
    _killings++;
 }