2012-04-10 31 views
0

我現在正在寫俄羅斯方塊,我有一個方法將數字逐一放到屏幕上的相同位置,方法在雙擊屏幕後開始工作,並在while循環中調用:無法實現俄羅斯方塊移動方法

while (gameState == gamePlaying) {} 

的問題是,我donn't知道如何UISwipeGesture甚至讓我moveLeftmoveRight方法的工作只是通過使用按鈕,因爲當投下方法的工作,我不能使用任何按鈕或手勢(如果我理解正確的話) 那麼,如何創建一個按鈕,比現在使用的方法具有更高的靈活性!(或如何使用UISwipeGestures在這種情況下?)

回答

1

我也會建議使用NSTimer來安排遊戲邏輯。如果你只是想執行一個後臺線程的操作,使得用戶界面不會阻止你可以使用例如:

-(void)performGameLogic 
{ 
    //Do the game logic 
} 

-(void)startGame 
{ 
    [self performSelectorInBackground:@selector(performGameLogic) withObject:nil]; 
} 

的NSTimer變種:

@interface Game 
{ 
    NSTimer * timer; 
} 

-(void)performGameLogic 
{ 
    //Do the game logic 
} 

-(void)startGame 
{ 
    timer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target:self selector:@selector(performGameLogic:) userInfo:nil repeats: YES]; 
} 

@end