2
我試圖在兩個圖像觸摸動作時發生。從我所看到的CGRecIntersectRect中完成此操作的最佳方式是,當它使用動畫循環中的圖像時,它的工作效果非常好。如果任何人都可以幫我弄清楚,那麼當這兩個圖像觸摸動作發生時,會驚人! `動畫過程中的圖像碰撞
- (無效)startanimation {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:2];
[UIView setAnimationDidStopSelector:@selector(animationdidstop) ];
_enemy1.center = CGPointMake(_enemy1.center.x +390, _enemy1.center.y);
[UIView commitAnimations];
}
-(void)animationdidstop
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:2];
[UIView setAnimationDidStopSelector:@selector(startanimation) ];
_enemy1.center = CGPointMake(_enemy1.center.x -390, _enemy1.center.y);
[UIView commitAnimations];
}
-(void)collision
{
if (CGRectIntersectsRect(_node.frame, _bounds1.frame)) {
NSLog(@"got to collision");
[_node setHidden:YES];
}
}
`
這部分後立即來了,是哪裏的問題。 _enemy1.frame似乎沒有認識到它的相互碰撞,或者我不確定問題到底是什麼,但這是我認爲問題所在。
-(void)collision
{
if (CGRectIntersectsRect(_node.frame, _enemy1.frame)) {
NSLog(@"got to collision");
[_node setHidden:YES];
}
}
}
CGRectIntersectRect爲什麼不工作? – huddie96
如何以及何時調用' - (void)collision'方法? – RaffAl