Iphone 两幅图像之间的碰撞

Iphone 两幅图像之间的碰撞,iphone,xcode,methods,uiimageview,collision-detection,Iphone,Xcode,Methods,Uiimageview,Collision Detection,我有两个图像image1和image2,当它们发生碰撞时,我想“做点什么”,但我不知道碰撞的代码,也不知道我们是否需要碰撞方法的计时器。我该怎么做呢?如果您安排一个计时器作为运行循环 [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(myRunloop) userInfo:nil repeats:YES]; 然后在运行循环中检查碰撞 - (void)myRunloop { // che

我有两个图像image1和image2,当它们发生碰撞时,我想“做点什么”,但我不知道碰撞的代码,也不知道我们是否需要碰撞方法的计时器。我该怎么做呢?

如果您安排一个计时器作为运行循环

[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(myRunloop) userInfo:nil repeats:YES];
然后在运行循环中检查碰撞

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

您完成了:-)

如果您计划一个计时器作为运行循环

[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(myRunloop) userInfo:nil repeats:YES];
然后在运行循环中检查碰撞

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

完成:-)

顺便说一句,计时器可能有点紧。利用间歇时间来调整计时器。这在一个小游戏中对我很有效。顺便说一句,计时器可能有点紧。利用间歇时间来调整计时器。不过,这在一个小游戏中对我起了作用。