2013-08-20 67 views
-2

我正在做一個簡單的遊戲,Xcode發現一個錯誤說有一個「使用未聲明的標識符'gameLoop'」。我怎樣才能解決這個問題?在Xcode中使用未聲明的標識符

// 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); 

回答

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);} 
+0

感謝現在它說,使用未申報的viewDidLoad – user2514477

+0

的你需要說 - (無效)viewDidLoad中,而不是(無效)viewDidLoad中 –

+0

你會看起來像PS感謝 – user2514477

相關問題