简单游戏 - 在得分后添加倒计时

时间:2012-04-10 23:51:42

标签: iphone objective-c timer

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

}

1 个答案:

答案 0 :(得分:0)

NSTimer应该有效。如果你很好奇,请看一下CADisplayLink