0

I use CGRectIntersectsRect()to see whenever a CCSprite collides with another CCSprite:

- (void)update3
{
    for (CCSprite *sprite in _monsters)
    {
        if (CGRectIntersectsRect(_rocket.boundingBox, sprite.boundingBox))
        {
            NSLog(@"Collide");
        }
    } 
}

This fires the log as long as the sprites touches each other, I just want to detect the first touch. Is this possible?

4

1 回答 1

1

当两个对象第一次接触时,将首先调用此碰撞代码。此时,为了防止进一步评估,你可以在你的怪物上设置一个属性,比如isInCollision当它是 时不检查相交的边界矩形true

当你想让你的怪物再次接收子弹时,设置isInCollisionfalse

于 2013-08-18T20:33:00.503 回答