2014-09-02 95 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