Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Gesture Recogniser crashing on level up

I am trying to implement a gesture recogniser and everything is working well until it comes to loading the next level, then at the next level stage, where can tap to go to the next level, if I use a gesture, the program crashes. My gesture recogniser is below.

- (void)didMoveToView:(SKView*)view {

    UIGestureRecognizer *spinner = [[UIPanGestureRecognizer alloc] initWithTarget:self     action:@selector(handlePanGesture:)];
    [self.view addGestureRecognizer:spinner];

}



- (void)handlePanGesture:(UIPanGestureRecognizer *)gestureRecognizer {

    CGPoint velocity = [gestureRecognizer velocityInView:self.view];

    if (velocity.y > 0) {

            NSLog(@"gesture went down");

    } else {

            NSLog(@"gesture went up");

    }
}

The problem may be in the way I am incrementing levels or implementing touch so here is the touches began method and the level increment code

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    BOMPlayerNode *playerNode = (BOMPlayerNode*)[self childNodeWithName:@"Player"];

    if (!self.restart) {

        for (UITouch *touch in touches) {
    CGPoint positionInScene = [touch locationInNode:self];

    int duration = 1.0;

    SKAction * actionMove = [SKAction moveTo:CGPointMake(positionInScene.x, positionInScene.y) duration:duration];
    [playerNode runAction:actionMove];

        }
    } else if ( self.restart && self.nextLevel ) {
        levelCount++;
        for (SKNode *node in [self children]) {
            [node removeFromParent];
        }


        BOMGamePlayScene *scene = [BOMGamePlayScene sceneWithSize:self.view.bounds.size];
        [self.view presentScene:scene];

    } else if ( self.restart && self.tryAgain ) {
        for (SKNode *node in [self children]) {
            [node removeFromParent];
        }


        BOMGamePlayScene *scene = [BOMGamePlayScene sceneWithSize:self.view.bounds.size];
        [self.view presentScene:scene];
    }

}

- (void) update:(NSTimeInterval)currentTime {

    if (GameOverConditions) {

        self.tryAgain = YES;
        self.restart = YES;
        [self performGameOver];

    } else if (NextLevelConditions) {

        self.restart = YES;
        self.nextLevel = YES;
        [self performNextLevel];

    }

}


- (void) performGameOver {
    if (!self.gameOverDisplayed) {
        BOMGameOverNode *gameOver = [BOMGameOverNode gameOverAtPosition:CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))];
        self.gameOverDisplayed = YES;
    }

}

- (void) performNextLevel {
    if (!self.nextLevelDisplayed) {
        BOMNextLevelNode *nextLevel = [BOMNextLevelNode     nextLevelAtPosition:CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))];
        self.nextLevelDisplayed = YES;
    }

}

Any help would be much appreciated.