2014-02-27 66 views
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]; 
     } 
    } 
    } 

回答

1

CoreAnimation這個東西很難做到這一點。我建議你留意了一下上SpriteKitCocos2d

雪碧套件 - 是設計,使強大的2D圖形 應用自如的框架。

的Cocos2D - 是構建2D遊戲,演示和其他 圖形/交互的應用程序的框架。

+0

CGRectIntersectRect爲什麼不工作? – huddie96

+0

如何以及何時調用' - (void)collision'方法? – RaffAl