-2

我正在制作一个简单的游戏,Xcode 发现一个错误说存在“使用未声明的标识符'gameLoop'”。我怎样才能解决这个问题?

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.


(void)viewDidLoad {
    [super viewDidLoad];
    gameState = kStateRunning;


    [NSTimer scheduledTimerWithTimeInterval: 1.0/60 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
    rockVelocity = CGPointMake (0, 0); 
    gravity = CGPointMake (0, kGravity);    

- (void)gameLoop {
    if (gameState == kStateRunning)
    {
        [self gameStatePlayNormal];
    }
    else if (gameState == kStateGameOver)
    {

    }
}

(void)gameStatePlayNormal {
    rockVelocity.y += gravity.y;

    rock.center = CGPoint(rock.center.x + ballVelocity.x,rock.center.y + rockVelocity.y);
4

1 回答 1

2

在 viewDidLoad 方法之后需要一个右括号。请注意,Objective C 中的方法需要在它们前面加上 - 或 +。

 -(void)viewDidLoad {
[super viewDidLoad];
gameState = kStateRunning;


[NSTimer scheduledTimerWithTimeInterval: 1.0/60 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
rockVelocity = CGPointMake (0, 0); 
gravity = CGPointMake (0, kGravity);   
}
 - (void)gameLoop {
   if (gameState == kStateRunning)
   {
       [self gameStatePlayNormal];
   }
    else if (gameState == kStateGameOver)
    {

    }
}

-(void)gameStatePlayNormal {
    rockVelocity.y += gravity.y;

    rock.center = CGPoint(rock.center.x + ballVelocity.x,rock.center.y + rockVelocity.y);}
于 2013-08-20T04:54:02.920 回答