Question

I have a collision handler detecting for a game over situation, however when the rocket lands (else if), the labels become visible no problems, but there is a second where the touch down even still registers, then the rocket takes off again, then the touch disables. Is there any obvious thing I'm doing wrong?

-(BOOL)ccPhysicsCollisionPreSolve:(CCPhysicsCollisionPair *)pair rocket:(CCNode *)nodeA landingPad:(CCNode *)nodeB{
//if travelling too fast on landing..
if (_rocket.physicsBody.velocity.y < maximumVerticalVelocity){
    _crashNotice.visible = TRUE;
     crashed = TRUE;
    [_rocket removeFromParentAndCleanup:YES];
    self.userInteractionEnabled = FALSE;

}else if (_rocket.physicsBody.velocity.y > 0.01){
    self.userInteractionEnabled = FALSE;

    //show game won state
    _scoreLabel.visible = FALSE;
    _showScoreLabel.visible = TRUE;

}return TRUE;
}
Was it helpful?

Solution

Instead of enable and disable touch, handle through bool value.

In class.h file declare this

 bool mAllowTouch;

In Init/onEnter :

-(void)onEnter
{
    [super onEnter];

    mAllowTouch = true;
    self.userInteractionEnabled = true;
}

In your function

-(BOOL)ccPhysicsCollisionPreSolve
{
       if(YOUR_CONDITION_TO_STOP_TOUCH)
       {
          mAllowTouch = false;
       }
       else 
       {
           mAllowTouch = true;
      }
}

In touch function, use mAllowTouch to process your touch.

-(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event 
{
    if(mAllowTouch)
    { 
         //handle touch here.
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top