0

I have an issue where I have a game over/stop function:

Hero.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");
}

GameScene.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];
}

that calls the stop function on every single collision the hero has with the obstacles. I only want it to call the stop function on the very first contact the hero has with the obstacles and ignore the following contacts. Any help would be great.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
DwemerTech
  • 11
  • 3
  • 1
    Set a BOOL to TRUE once the first contact is made. Subsequent contacts can check the BOOL value and ignore everything if it's set to TRUE. – sangony Jan 10 '15 at 23:02
  • I cannot seem to find where the first contact is made in the code. I assumed it would be under didBeginContact, but the BOOL didn't work there. – DwemerTech Jan 11 '15 at 02:16
  • Where are you declaring the BOOL? – sangony Jan 11 '15 at 16:20

0 Answers0