Alfro
Alfro

Reputation: 1544

SKScene doesn't change in spriteKit since today

I'm having problems since today in my game, when I try to change scene. It's a bit funny, when I collide with enemies I got no problem. I call my resetScene function which create the gameOver scene and shows it. But when I fall in a hole, and make the same call, I my game doesn't change the scene. I've added a new label in resetScene function, so when compiler go in this code, will add a layer. Now when I get in a hole, I got the layer but the scene doesn't change. It's a bit confusing. I'll show code and screenshots:

This is the only place when it works:

            /**********
        if hero collide with enemy
                              *******/
-(void)didBeginContact

{
        if(bodyB.physicsBody.categoryBitMask == enemy)
        {
            if(!YES == _deadAnimation)
            {
                if(_stars > _bestScore )
                {
                    _bestScore = _stars;

            }
            if(_bestScore> [self.prefs integerForKey:@"bestScore"])
            {
                [self.prefs setInteger:_bestScore forKey:@"bestScore"];
            }
            _deadAnimation = [self runDeadAnimation]; // (only return BOOL YES for the moment)


            [self resetScene];
        }
    }
}

Now this is where it doesn't works:

-(void)didSimulatePhysics
{


/* reset scene if fall*/
if(self.hero.position.y < 100)
{
    _deadAnimation = [self runDeadAnimation]; // (only return BOOL YES for the moment)
    [self resetScene];

}
/* reset scene if stay behind */
if(self.hero.position.x<10 ){
    [self resetScene];
}

}

And this is my reset function:

{
[_hero removeFromParent];
[self addDebugLayer:@"dead" xPosition:200 yPosition:200 childPos:_hero.position.y infinite:YES]; // <<-----(add a new SKLabel)

SKScene *mundo1  = [[XYZGameOver alloc] initWithSize:self.size];
SKTransition *doors = [SKTransition fadeWithDuration:0.2];
[self.view presentScene:mundo1 transition:doors];


}

As you can see, the layer "muerto" (dead) is added with the y position but the scene haven't changed

Upvotes: 2

Views: 182

Answers (1)

heisenberg
heisenberg

Reputation: 26

In case of didSimulatePhysics, do the transition with 0 duration. You can use some BOOL to check which kind of Game Over it is. It worked for me. Don't know the reason behind this though.

Upvotes: 1

Related Questions