我正在使用Windows 8 metro应用程序c#创建一个pacman游戏。
我目前在“IntersectsWith”上有一些错误。
如下图所示,我实际上是想让pacman吃掉颗粒。任何人都可以告诉我为什么代码上有错误? :
代码:
var rectPacman = pacman.GetRect(cnvMain);
bool gotPellet = false;
foreach (var pellet in pellets)
{
if (pellet.Visibility == Visibility.Visible)
{
var rectPellet = pellet.GetRect(cnvMain);
var pelletCellPoint = pellet.GetCellPoint();
if (rectPacman.IntersectsWith(rectPellet))
{
gotPellet = true;
pellet.Visibility = Visibility.Collapsed;
AddPellet(pellet);
mazeValues[(int)pelletCellPoint.X, (int)pelletCellPoint.Y] = ' ';
break;
}
}
}
显示错误:
'Windows.Foundation.Rect' does not contain a definition for 'IntersectsWith' and no extension method 'IntersectsWith' accepting a first argument of type 'Windows.Foundation.Rect' could be found (are you missing a using directive or an assembly reference?)
答案 0 :(得分:2)
正如编译器错误所述,类型Windows.Foundation.Rect
(http://msdn.microsoft.com/en-us/library/windows/apps/windows.foundation.rect)没有InteresectsWith
方法。
System.Drawing.Rectangle
(http://msdn.microsoft.com/en-us/library/system.drawing.rectangle.aspx)可以,但您似乎正在编写WinRT应用程序,常规.Net系统库不适用。