Sprite kit 如何在第一次接触时只调用一次方法?

Sprite kit 如何在第一次接触时只调用一次方法?,sprite-kit,collision-detection,skphysicscontact,Sprite Kit,Collision Detection,Skphysicscontact,我有一个问题,我有一个游戏结束/停止功能: 英雄 +(id)hero//The hero { JBHero *_hero = [JBHero spriteNodeWithTexture:heroTexture1]; _hero.name = @"hero"; return _hero; } - (void)stop { self.physicsBody.contactTestBitMask = button2Category; /*Setting contact to

我有一个问题,我有一个游戏结束/停止功能:

英雄

+(id)hero//The hero
{
JBHero *_hero = [JBHero spriteNodeWithTexture:heroTexture1];
_hero.name = @"hero";
    return _hero;
}

- (void)stop
{
    self.physicsBody.contactTestBitMask = button2Category;
    /*Setting contact to the only node I want contact with when gameover is called*/
    self.physicsBody.allowsRotation = YES;
    [self removeAllActions];
    NSLog(@"STOP");
}
游戏场景

-(void)gameOver
{
    self.isGameOver = YES;
    [hero stop];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */
    if (! self.isStarted){
        [self start];//Start method
        self->hero.physicsBody.dynamic = YES;
        }
    else if (self.isGameOver){
        [self clear];//Reset scene
    }
    else [hero jump];
}
这将在英雄与障碍物的每次碰撞中调用停止功能。我只希望它在英雄与障碍物的第一次接触时调用停止功能,并忽略以下接触。
任何帮助都会很好。

一旦第一次接触,将BOOL设置为TRUE。后续联系人可以检查BOOL值,如果设置为TRUE,则忽略所有内容。我似乎无法在代码中找到第一个联系人的位置。我以为它会在didBeginContact下,但是BOOL在那里不起作用。你在哪里申报BOOL?