Search code examples
iosiphonexcode5touchesbegan

Error with touchesBegan code


When I write

@implementation GameViewController

-(IBAction)StartGame:(id)sender{

    StartGame.hidden = YES;

    BirdMovement = [NSTimer scheduledTimerWithTimeInterval:0.05
    target:self selector:@selector(BirdMoving) userInfo:nil repeats:YES];

}

-(void)BirdMoving{

    Bird.center = CGPointMake(Bird.center.x, Bird.center.y - BirdFlight);

    BirdFlight = BirdFlight - 5;

    if (BirdFlight < -15) {
        BirdFlight = -15;

        if (BirdFlight > 0) {
            Bird.image = [UIImage imageNamed:@"3.png"];

        }

        if (BirdFlight < 0) {
            Bird.image = [UIImage imageNamed:@"4.png"];
        }

}


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

    BirdFlight =30;

}

it says that I use an undeclared identifier touchesBegan: Please help me :)


Solution

  • You forgot the closing right brace (}) for the if (BirdFlight < -15) statement in your BirdMoving method.

    In Xcode, choose Edit > Select All (or press A). Then choose Editor > Structure > Re-Indent (or press controlI). This will make the problem obvious.