我有2张图片(bar和greenBall1)。酒吧可以上下移动取决于用户的反应。而greenBall1正在屏幕上移动。如果两个图像相互接触,我想进行图像碰撞,greenBall1将改变其速度。我对greenBall1的代码如下。如何在使用Windows Phone应用程序的Windows Phone 8的C#中执行图像冲突?
private void OnUpdate(object sender, object e)
{
Canvas.SetLeft(this.GreenBall1, this.greenBallVelocityX + Canvas.GetLeft(this.GreenBall1));
Canvas.SetTop(this.GreenBall1, this.greenBallVelocityY + Canvas.GetTop(this.GreenBall1));
var greenBallPositionX1 = Canvas.GetLeft(this.GreenBall1);
var greenBallPositionY1 = Canvas.GetTop(this.GreenBall1);
var maximumGreenBallX = ActualWidth - this.GreenBall1.ActualWidth;
var maximumGreenBallY = 400 - this.GreenBall1.ActualHeight; //Improvise: Instead of 360, get maximum height of canvas
if (greenBallPositionX1 > maximumGreenBallX || greenBallPositionX1 < 0)
{
this.greenBallVelocityX *= -1;
}
if (greenBallPositionY1 > maximumGreenBallY || greenBallPositionY1 < 0)
{
this.greenBallVelocityY *= -1;
}
}
你想要做圈的碰撞? http://stackoverflow.com/questions/1736734/circle-circle-collision –
不,我希望做一个矩形的碰撞。基本上我就像在球击中矩形杆时试图做出反弹一样,现在球会穿过我的酒吧。 –
是否限制像Pong一样上下移动? –