[英]'System.Windows.Rect' does not contain a definition for 'Intersects' for C#
我在使用Microsoft Visual Studio 2012的Windows Phone 8的Windows Phone App上發生碰撞。我使用Rect制作了球的矩形邊框。 我收到此錯誤。 'System.Windows.Rect'不包含'Intersects'的定義,找不到擴展方法'Intersects'接受類型為'System.Windows.Rect'的第一個參數(您是否缺少using指令或程序集引用?)代碼如下。
var greenBallPositionX1 = Canvas.GetLeft(this.greenBall1);
var greenBallPositionY1 = Canvas.GetTop(this.greenBall1);
Rect r1 = new Rect(greenBallPositionX1, greenBallPositionY1, greenBall1.ActualWidth, greenBall1.ActualHeight);
var blueBallPositionX1 = Canvas.GetLeft(this.blueBall1);
var blueBallPositionY1 = Canvas.GetTop(this.blueBall1);
Rect r2 = new Rect(blueBallPositionX1, blueBallPositionY1, blueBall1.ActualWidth, blueBall1.ActualHeight);
if (r1.Intersects(r2))
{
MessageBox.Show("Collision Detected");
}
你自己的相交可以寫成
public bool Intersects(Rect r1,Rect r2)
{
r1.Intersect(r2);
if(r1.IsEmpty)
{
return false;
}
else
{
return true;
}
}
那么你可以使用
if(Intersects(r1,r2))
{
MessageBox.Show("Collison Detected");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.