2014-03-02 76 views
1

我試圖讓'luke'跳過一個對象來確保遊戲不會結束,他會這樣做,但即使他避免了遊戲仍然結束的對象,就好像luke還沒有離開他在動畫期間的原始位置。Collision detection&animateWithDuration

我在-(void)touchesBegin中使用了UIView animateWithDuration來試圖實現這一點。

[UIView animateWithDuration:3 
       animations:^ 
{ 
    luke.center = CGPointMake(luke.center.x +0, luke.center.y -60); 
} 
       completion:^(BOOL completed) 
{ 
    if (completed) 
    { 
     [UIView animateWithDuration:3 
        animations:^  
      { 
       luke.center = CGPointMake(luke.center.x +0, luke.center.y +60); 
      }]; 
    } 

我也使用CGRectIntersectsRect告訴我,當兩個物體發生碰撞

-(void)collision { 

if (CGRectIntersectsRect(luke.frame, smallboulder.frame)) { 
    [self endgame]; 
} 

if (CGRectIntersectsRect(luke.frame, largeboulder.frame)) { 
    [self endgame]; 

} 

if (CGRectIntersectsRect(luke.frame, cactus.frame)) { 
    [self endgame]; 
} 

終於我可以使用動畫設置爲NSArray跳時表現出的運動。

非常感謝

JP

+0

爲什麼你使用這種過時的Xcode版本? –

+0

我正在使用一個macbook4.1,我不能升級雪豹以上。因此過時的版本 – user3369583

+0

你有更現代的PC嗎?您可以將小牛安裝在虛擬機中並開展工作。 –

回答

1

當使用UIView動畫的方法動畫各種屬性,動畫實際上是在一些所謂的表示層進行。但是,當您使用視圖的訪問器時,它將訪問模型層(而不是表示層),該模型層保存最新值(因此它保留動畫後的指定幀)。

你應該檢查「luke」的位置是否使用luke.layer.presentationLayer.frame

+1

謝謝 - 固定 – user3369583

+0

@ user3369583這很好聽。 –