两个图像之间的碰撞

时间:2011-06-28 09:16:23

标签: iphone xcode methods uiimageview collision-detection

我有两个图像image1和image2,我想在碰撞时“做点什么”,但我不知道碰撞的代码,如果我们需要一个碰撞方法的计时器。我该怎么办呢?

1 个答案:

答案 0 :(得分: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.. //
    }
}

你完成了: - )

相关问题