我在使用这种方法时遇到问题。我有两个显然包含在彼此内部的矩形。(我什至手动绘制了它们的坐标以确保。)当我使用 CGRectContainsRect 比较这两个矩形时,它返回 false。对于我的一生,我已经尝试了一切,搜索了网络,但我找不到这个问题的答案。有人知道为什么吗?我在调试时包含了 CGRects 的值,以表明它们肯定在彼此之内。
-(bool)checkBoundingBox {
bool returnItem = YES;
//Checks for sprite interaction
for (int i = 0; i < [arrGameItems count]; i++) {
CGRect rect2 = [[self getChildByTag:1] boundingBox];
CGRect rect1 = [[self getChildByTag:3] boundingBox];
// rect1 = CGRectStandardize(rect1);
// rect2 = CGRectStandardize(rect2);
if (CGRectContainsRect(rect2, rect1)) {
CCLOG(@"removed child b*&ch");
[self removeChildByTag:[arrGameItems count] cleanup:YES];
returnItem = NO;
}
}
CCLOG(@"g-dammit");
return returnItem;
}
rect1 原点 x = 141 y = 76,高度 = 25,宽度 = 25
rect2 原点 x = 127 y = 91,高度 = 25,宽度 = 25