jeudi 13 août 2015

Adding Enemies While Paused

When I pause the game and wait some time, then resume the game, an alien ship is immediately added. How do I make it so that the 'timer' doesn't continue once the game is paused?

My Code:

@implementation GamePlayScene
-(void) didMoveToView:(SKView *)view {
               ...
    self.addAlienTimeInterval = [Util randomWithMin:10 max:25];
    self.timeSinceLastAlien = 0;
               ...
}
-(void) update:(NSTimeInterval)currentTime{
    if (!_isGamePaused){
        if (self.lastUpdateTimeInterval){
            self.timeSinceLastAlien += currentTime - self.lastUpdateTimeInterval;
        }
        if (self.timeSinceLastAlien > self.addAlienTimeInterval && !self.gameOver){
            [self addAlienShip];
            self.timeSinceLastAlien = 0;
        }
        self.lastUpdateTimeInterval = currentTime;
                ...
}
@end



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire