我正在用 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];
}