NSTimer当得分更新将我的UIImages重置为原始状态目标c?

时间:2013-01-20 16:02:05

标签: objective-c nstimer game-loop

我刚开始学习Xcode和目标c,我已经制作(并发布)了一些运行良好的基本应用程序,我想尝试制作游戏。我已经开始了,到目前为止它一直很好。香港专业教育学院一直在使用NSTimer设置像这样的游戏

[NSTimer scheduledTimerWithTimeInterval:1.0/100 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];

然后

- (void) gameStatePlayNormal    {
    speed = obstacleVelocity.x;
    obstacleVelocity = CGPointMake(speed+.002, 0);
    gameOver.text = @"";
    reset.hidden = 1;

    obstacle.center = CGPointMake(obstacle.center.x - obstacleVelocity.x, obstacle.center.y - obstacleVelocity.y);

    if (obstacle.center.x <= 0){
        y = random() %280;
        obstacle.center = CGPointMake(x, y);

        (gameState = kstateRunning);
    }
    if (CGRectIntersectsRect(ball.frame, obstacle.frame)){
        gameState = kstateGameOver;

    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event    {
    if (ball.center.x <= self.view.bounds.size.width/2) {
        UITouch *touch = [touches anyObject];
        CGPoint toPoint = [touch locationInView:self.view];
        [ball setCenter:toPoint];
        if (ball.center.x >= self.view.bounds.size.width/2) {
            ball.center = CGPointMake(self.view.bounds.size.width/2, ball.center.y);
        }
    }
}

一切正常, 但是当谈到得分时,UIImages只是保持原点,但得分上升

if (gameState == kstateRunning)  {
   score.text = [NSString stringWithFormat:@"%.0i", addtoscore ];
   addtoscore = (int)(speed * 50);  
    [self gameStatePlayNormal];

(P.S。这就是 - (void)gameLoop {})  任何人都可以想到我做错了什么或者另外一种方式去做什么?我全都耳朵, 提前谢谢!

0 个答案:

没有答案