0

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

英雄.m

+(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");
}

游戏场景.m

-(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];
}

在英雄与障碍物发生的每一次碰撞中调用停止函数。我只希望它在英雄与障碍物的第一次接触时调用停止功能,并忽略以下接触。任何帮助都会很棒。

4

0 回答 0