使用此代码来尝试检测两个图像之间的冲突,其中一个图像处于动画中,但不起作用。使用UIAnimation检测冲突
[UIView animateWithDuration:5 animations:^{
bird.center = CGPointMake(bird.center.x, 600);
fallTimer = [NSTimer scheduledTimerWithTimeInterval:.001 target:self selector:@selector(check) userInfo:nil repeats:YES];
}];
-(void)check {
if (CGRectIntersectsRect(bird.frame, cat.frame)) {
NSLog(@"YES");
}
}
如何检测碰撞?
你的时间间隔是可笑的小(0.001秒)。它在代码中看起来像鸟的位置是静态的。猫是否在移动,你可以在猫动画中进行检查吗? –
猫是动态的,而猫是静态的。 –