2014-09-02 89 views
0

我环顾四周,找不到一个简单的方法。我有一个动画在碰撞发生时播放,尽管动画无法越过第一帧,直到碰撞检测继续发射时物体完全分离。如何暂时停止碰撞检查

有谁知道如何强制动画播放所有的方式或碰撞检测只检查一次? (尽管之后需要再次运行碰撞检测以重复该过程)。

if (CGRectIntersectsRect(Heli.frame, AstroidBig.frame)) { 
     animation2.animationImages = [NSArray arrayWithObjects: 
            [UIImage imageNamed:@"Image 1"], 
            [UIImage imageNamed:@"Image 2"], 
            [UIImage imageNamed:@"Image 3"], 
            nil]; 
     [animation2 setAnimationRepeatCount:1]; 
     animation2.animationDuration = 0.4; 
     [animation2 startAnimating]; 
     [self performSelector:@selector(enemyreset) withObject:nil afterDelay:1]; 
} 

'enemyreset'是一个函数,它会将对象从碰撞点重置回游戏中。

回答

0

在上述方法中设置一个标志,表明您正在进行动画制作(您将需要将其添加为属性)。如果您尚未制作动画,请仅启动动画。然后重置enemyreset方法中的标志。

if (CGRectIntersectsRect(Heli.frame, AstroidBig.frame)) { 
    if (!self.alreadyAnimating) { 
     animation2.animationImages = [NSArray arrayWithObjects: 
            [UIImage imageNamed:@"Image 1"], 
            [UIImage imageNamed:@"Image 2"], 
            [UIImage imageNamed:@"Image 3"], 
            nil]; 
     [animation2 setAnimationRepeatCount:1]; 
     animation2.animationDuration = 0.4; 
     [animation2 startAnimating]; 
     [self performSelector:@selector(enemyreset) withObject:nil afterDelay:1]; 
     self.alreadyAnimating = YES; 
    } 
} 
+0

你能解释多一点@pbasdf吗? 最后我无法让它工作。会因为我对编码的理解有限。 – user3230481 2014-09-03 04:37:43

+0

当然,如果你可以添加一些关于你的问题的更多细节。特别是上面的代码在哪个方法中?如何更新Heli.frame和AsteroidBig.frame? – pbasdf 2014-09-03 06:27:38