0

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

}
4

1 回答 1

0

NSTimer应该可以工作。如果你好奇,也可以看看CADisplayLink

于 2012-04-11T00:34:36.320 回答