我试图让这个 SKScene 在游戏结束时出现在场景的中间,这样之前的场景在背景中仍然可见(类似于 flappy bird 的结尾)。这是我希望它出现的图像:
到目前为止,这是我制作的代码:
在游戏场景中:
-(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]];
}
在游戏结束的头文件中:
@class testScene;
@interface gameOverScene : SKScene
@property (weak, nonatomic) testScene *gameScene;
-(instancetype)initWithScore:(NSInteger)score;
@end
在游戏结束的实现中:
-(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;
}
但这是我在模拟器上测试它时得到的:
带有以下错误消息:
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.
谁能告诉我哪里出错了,我该如何解决?谢谢。如果需要任何额外信息,请告诉我。