2014-02-27 70 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