I'm trying to make this SKScene appear in the middle of the scene at the end of the game, so that the previous scene is still visible in the background (similar to that of the ending of flappy bird). This is an image of how I want it to appear:
So far this is the code I've made:
in the game scene:
-(void)dieFrom:(SKNode*)killingDebris {
_touched = YES;
if (_touched == YES) {
beatLevel = YES;
NSLog(@"touched");
[self runAction:[SKAction sequence:@[
[SKAction runBlock:^{
[_goodSquare removeFromParent];
}],
[SKAction runBlock:^{
level2Achieved = [[NSUserDefaults standardUserDefaults] integerForKey:@"newLevelAchieved"];
if (beatLevel == YES) {
level2Achieved = 2;
}
[[NSUserDefaults standardUserDefaults] setInteger:level2Achieved forKey:@"newLevelAchieved"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self removeAllChildren];
}],
[SKAction waitForDuration:1.5],
[SKAction runBlock:^{
[self endGame];
}],
]]];
}
}
-(void)endGame {
[self removeAllActions];
gameOverScene *gameOverNode = [[gameOverScene alloc] initWithScore:self.score];
gameOverNode.gameScene = self;
gameOverNode.position = CGPointMake(self.scene.size.width/2, -150);
[self addChild:gameOverNode];
[gameOverNode runAction:[SKAction moveToY:self.scene.size.height/2 duration:0.6]];
}
In the game over's header file:
@class testScene;
@interface gameOverScene : SKScene
@property (weak, nonatomic) testScene *gameScene;
-(instancetype)initWithScore:(NSInteger)score;
@end
In the game over's implementation:
-(instancetype)initWithScore:(NSInteger)score {
if (self = [super init]) {
self.userInteractionEnabled = YES;
self.zPosition = 5.0;
SKSpriteNode *bg = [SKSpriteNode spriteNodeWithColor:[SKColor redColor] size:CGSizeMake(280, 300)];
bg.alpha = 0.6;
[self addChild:bg];
}
return self;
}
BUT this is what I'm getting when I test it on the simulator:
With the following error messages:
2014-05-11 15:22:05.502 test2[2825:60b] SKScene: Setting the zPosition of a SKScene has no effect.
2014-05-11 15:22:05.503 test2[2825:60b] SKScene: Setting the position of a SKScene has no effect.
2014-05-11 15:22:05.504 test2[2825:60b] SKScene: Animating the position of a SKScene has no effect.
Can anyone tell me where I've gone wrong, and how I can fix it?
Thanks.
Please let me know if any extra info is needed.