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");
}
}
誰か助けてください。