2014-03-02 52 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这很好听。 –