I'm making a game using SpriteKit. I'm checking if the player is dead in the update method, like this:
-(void)update:(CFTimeInterval)currentTime
{
if (self.player.dead) {
[self gameOver];
}
}
The gameOver
method is the following:
-(void)gameOver {
SKView * skView = (SKView *)self.view;
GameOverScene *gameOver = [GameOverScene sceneWithSize:skView.bounds.size];
gameOver.scaleMode = SKSceneScaleModeAspectFill;
[skView presentScene:gameOver transition:[SKTransition doorsOpenHorizontalWithDuration:1.0]];
}
For some reason the GameOver
scene is not being presented, instead the update method of the current screen keeps getting called. What am I doing wrong?
I think the problem may be that the self.player.dead flag keeps evaluating to YES over and over again inside the update method, calling [self gameOver] numerous times and never actually completing the transition due to the 1 second duration; you could easily test this with a breakpoint or logging. Try calling self.player.dead = NO in the -(void)gameOver method before you present the new scene.
Try the following and see if it makes a difference:
- (void)gameOver {
SKScene *gameOver = [[GameOverScene alloc] initWithSize:self.size];
SKTransition *doors = [SKTransition doorsOpenVerticalWithDuration:1.0];
[self.view presentScene:gameOver transition:doors];
}
Also, make sure that gameOver is being called from the current scene.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.