我有 2 张图像,我需要正确地碰撞它们。我尝试了许多解决方案,但无法正确碰撞它们。
这是图片
图 1
图 2
我尝试了 CGRectIntersectsRect(),但它无法正常工作,因为由于框架问题,图像在实际相遇之前就发生了碰撞。请帮我。
我也尝试使用 Sprite Kit,但对我有用。
编辑 1:
试过这段代码,但它不工作或很慢:
- (void) checkIntersectionOfRect1 :(CGRect) frame1 Rect2 : (CGRect) frame2 {
CGAffineTransform cg1 = CGAffineTransformIdentity;
CGMutablePathRef *cgPath1 = CGPathCreateWithRect(frame1,&cg1);
CGAffineTransform cg2 = CGAffineTransformIdentity;
CGMutablePathRef *cgPath2 = CGPathCreateWithRect(frame2,&cg1);
ANPathBitmap * bm1 = [[ANPathBitmap alloc] initWithPath:cgPath1];
ANPathBitmap * bm2 = [[ANPathBitmap alloc] initWithPath:cgPath2];
[bm1 generateBitmap];
[bm2 generateBitmap];
ANPathIntersection * intersection = [[ANPathIntersection alloc] initWithPathBitmap:bm1 anotherPath:bm2];
if ([intersection pathLinesIntersect:&CGPointZero]) {
NSLog(@"intersect");
[self endGame];
}
else {
NSLog(@"No intersection");
}
}
请有人帮忙。