【问题标题】:collision between two images两个图像之间的碰撞
【发布时间】:2011-06-28 09:16:22
【问题描述】:

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

【问题讨论】:

    标签: iphone xcode methods uiimageview collision-detection


    【解决方案1】:

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

    [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.. //
        }
    }
    

    你已经完成了:-)

    【讨论】:

    • 顺便说一句,那个计时器可能有点紧。玩弄间隔以使计时器正确。不过,这在一个小游戏中对我有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多