gpt4 book ai didi

ios - 为什么我不能将一个 SKScene 添加到另一个 SKScene?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:00:51 27 4
gpt4 key购买 nike

我试图让这个 SKScene 在游戏结束时出现在场景的中间,这样之前的场景在背景中仍然可见(类似于 flappy bird 的结局)。这是我希望它如何显示的图像:

enter image description here

到目前为止,这是我编写的代码:

在游戏场景中:

-(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;
}

但这就是我在模拟器上测试时得到的结果:enter image description here

错误信息如下:

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?

来自 SKScene reference page 的概述部分:

A scene is the root node in a tree of Sprite Kit nodes (SKNode).

因为一棵树只能有一个根,所以任何 SKNode 图只有一个场景。

要解决此问题,请使用 SKNode(显然不是 SKScene)来包含您的游戏结束显示。然后,您可以将该节点添加到现有场景中。

关于ios - 为什么我不能将一个 SKScene 添加到另一个 SKScene?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23596921/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com