2011-06-28 63 views
1

我有两个图像image1和image2,我想在碰撞时“做些什么”,但我不知道碰撞的代码,以及碰撞方法是否需要定时器。我该怎么做?两个图像之间的碰撞

回答

1

如果您安排一个计时器作为runloop

[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(myRunloop) userInfo:nil repeats:YES]; 

,然后在runloop您检查碰撞

- (void)myRunloop 
{ 
    // check collision 
    if(CGRectIntersectsRect(image1.frame, image2.frame)) 
    { 
     // ..do your stuff.. // 
    } 
} 

你:-)完成

+0

顺便说一句,这计时器可能有点紧张。随着时间间隔来玩弄定时器。尽管如此,这对我来说很有用。 – Jake