我正在使用Objective-C创建一个简单的网球游戏。目前,当玩家或计算机得分时,它会给出一个“点击开始”并释放球的消息(将拇指放在球拍上以及另一个拇指点击它开始时有点尴尬。)
如何在游戏中添加计时器,以便我不必在每次得分后点击?
(此代码是新游戏和分数时的重置方法)
{
self.gameState = kGameStatePaused;
ball.center = self.view.center;
if(newGame)
{
if(computerScoreValue > playerScoreValue)
{
tapToBegin.textAlignment = UITextAlignmentCenter;
tapToBegin.text = @"Computer Wins!";
AudioServicesPlaySystemSound(booFileID);
}
else
{
tapToBegin.textAlignment = UITextAlignmentCenter;
tapToBegin.text = @"You Win!";
AudioServicesPlaySystemSound(clappingFileID);
}
computerScoreValue = 0;
playerScoreValue = 0;
}
else
{
tapToBegin.textAlignment = UITextAlignmentCenter;
tapToBegin.text = @"Tap to Begin";
}
playerScore.text = [NSString stringWithFormat:@"%d",playerScoreValue];
computerScore.text = [NSString stringWithFormat:@"%d",computerScoreValue];
}