2012-04-22 43 views
0

的错误我有一个代码,但在这段代码有错误,我不知道为什么我有这个错误。 因为我希望我的球击中至少边境大豆屏幕我把这个代码。 你可以看到我的代码:如何纠正这一计划

CGPoint ballCenter = ball.center; 
CGRect ballRect = CGRectMake(50, 73, 50, 50); // an arbitrary location for the ball, you would normally use the frame property of the ball here 
CGRect s = [UIScreen mainScreen].bounds; 
CGRect adjustedScreenRect = CGRectMake(s.x-50 // take the ball's (width or height) and divide it by two to get the distance to the center. Then multiply it by two and subtract from the appropriate dimension(x offset (width), y offset (height), width (width), height (height)). 
BOOL isOnScreen = CGRectContainsPoint(adjutedScreenRect, ballCenter); 
// do whatever with the BOOL from the above line... 

我有一个错误在这行:

CGRect adjustedScreenRect = CGRectMake(s.x-50 // take the ball's (width or height) and divide it by two to get the distance to the center. Then multiply it by two and subtract from the appropriate dimension(x offset (width), y offset (height), width (width), height (height)). 
BOOL isOnScreen = CGRectContainsPoint(adjutedScreenRect, ballCenter); 

和错误是X“在结构的CGRect‘’没有名为成员”。

感谢您的帮助

答案是CGRect adjustedScreenRect = CGRectMake(s.origin.x-50
BOOL isOnScreen = CGRectContainsPoint(adjutedScreenRect, ballCenter);

但我有BOOL预期的错误)。

你能帮我

回答

5

我想你的意思s.origin.x,不s.x。由于的CGRect是一个CGPoint和CGSize,直接访问的CGRect的x值的结构是不可能没有指定要第一次访问该结构的一部分。

编辑:

你从来没有真正关闭的CGRect的括号,或满足所有4个参数。试试这个:

CGRectMake(s.origin.x-50, s.origin.y, width,height); 
+0

是的,就是我刚才说的。 – 2012-04-22 18:50:14

+0

我有“预期)”错误与BOOL – AddGame 2012-04-22 19:29:28

+0

编辑与问题的代码行你的帖子,我会看看我能做些什么。 – CodaFi 2012-04-22 19:31:52