lwf233 2017-12-07 02:43 采纳率: 0%
浏览 881
已结题

wpf碰撞后运动问题,程序停止运行

两个小球碰撞之后,被撞的小球运动代码如下,但是在运行中,两个小球碰撞之后程序停止运行,下面的代码有什么问题吗?

public void CollionPMoveStop()
{
CollionP.Name

= "CollionP";
this.RegisterName(CollionP.Name

, CollionP);

        Thickness th = CollionP.Margin;
        double dx = 0;
        double dy = 0;
        double Left = CollionP.Margin.Left;
        double Top = CollionP.Margin.Top;
        double t1 = Math.Abs(xVelocity) / Acceleration;
        double t2 = Math.Abs(yVelocity) / Acceleration;
        double t;
        if (t1 > t2)
            t = t1;
        else
            t = t2;

        ThicknessAnimationUsingKeyFrames myThicknessAnimation =
            new ThicknessAnimationUsingKeyFrames();
        myThicknessAnimation.KeyFrames = new ThicknessKeyFrameCollection();

        while (Math.Abs(xVelocity)!=0  || Math.Abs(yVelocity)!=0)
        {
            if (CollionP.Margin.Left < PhysicsPaper.ActualWidth - 50  && CollionP.Margin.Left>50  && CollionP.Margin.Top>50 && CollionP.Margin.Top<PhysicsPaper.ActualHeight-50)
            {
                dx += xVelocity * 30 / 1000;
                dy += yVelocity * 30 / 1000;
                myThicknessAnimation.KeyFrames.Add(new LinearThicknessKeyFrame
                    (new Thickness(Left + dx, Top+dy, PhysicsPaper.ActualWidth - Left - dx - CollionP.Width, PhysicsPaper.ActualHeight - Top - dy - CollionP.ActualHeight)));

                if(xVelocity>0)
                    xVelocity -= Acceleration * 30 / 1000; 
                else if (xVelocity < 0)
                    xVelocity += Acceleration * 30 / 1000;
                if (yVelocity > 0)
                    yVelocity -= Acceleration * 30 / 1000;
                else if (yVelocity < 0)
                    yVelocity += Acceleration * 30 / 1000;

            }
            else    
                break;


        }
        MouseLDown = false;

        myThicknessAnimation.Duration = new Duration(TimeSpan.FromSeconds(t));

        myStoryboard = new Storyboard();
        myStoryboard.Children.Add(myThicknessAnimation);
        Storyboard.SetTargetName(myThicknessAnimation, CollionP.Name 

);
Storyboard.SetTargetProperty(myThicknessAnimation, new PropertyPath(Ellipse.MarginProperty));
myStoryboard.Begin(this);
}

  • 写回答

4条回答 默认 最新

  • qq_30698805 2017-12-07 05:45
    关注

    要处理两个检测两个物体的碰撞,然后把结果反馈给被碰撞的对象

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致
  • ¥15 禅道二次开发编辑版本,上传不了发行包