【问题标题】:Previous skscene is presenting without any call to present scene. Its like it was running in the background of my new scene先前的 skscene 正在呈现,而没有任何对当前场景的调用。就像它在我的新场景的背景中运行
【发布时间】:2014-08-01 21:50:15
【问题描述】:
       `SKView *skView = (SKView *) self.view;
        SKScene *scene = [MyScene sceneWithSize:skView.bounds.size];
        scene.scaleMode = SKSceneScaleModeAspectFill;
        [skView presentScene:scene];`

所以 MyScene 是您在开始游戏时呈现的主页。在选择地图并在游戏中失败后,如果您按下按钮返回主页并直接返回游戏的地图部分 我点击的地图会随机加载到视图中。任何帮助都会很棒,我没有收到错误,因为它只是加载到视图中并开始游戏。

好的,这里是主页场景中的代码,将您发送到部分屏幕

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//Called when a touch begins
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];

if([node.name isEqualToString:@"playButton"])
{

    SKView *skView = (SKView *) self.view;
    SKScene *scene = [SectionsScreen sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;
    [skView presentScene:scene];
}
}

然后,一旦您选择了第一部分,您就会转换到视图控制器,其中所有地图都加载到其中。

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
node.xScale = 1;
node.yScale = 1;
for (SKSpriteNode *label in self.sectionNumAra)
{
    if([[@"section" stringByAppendingString:label.name] isEqualToString:node.name])
    {
        label.xScale = 1;
        label.yScale = 1;
    }
}

if([node.name isEqualToString:@"section1"])
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"closeScene"         object:nil];
    MainViewController *main = [[MainViewController alloc]init];
    UIViewController *vc = self.view.window.rootViewController;
    [vc presentViewController: main animated: YES completion:nil];
}

这是到那个的过渡。

在此处选择地图过渡到 skscene 后

SKView *skView = (SKView *) self.view;
SKScene *scene = nil;
//Continue to make if statements to open the correct map.
if([[GameData sharedGameData].mapChosen isEqualToString:@"FirstMap"])
{
    scene = [FirstMap sceneWithSize:skView.bounds.size];
}
scene.scaleMode = SKSceneScaleModeAspectFill;
[skView presentScene:scene];

到目前为止一切都很好......现在一旦“游戏结束警报弹出,如果您选择返回部分屏幕(这是一个场景),您可能会回到那里。但点击一个部分后,您会不允许进入。我将先前的地图或先前的视图控制器直接加载到该场景中。

【问题讨论】:

  • 这里的代码显然是有效的。我们需要更多才能有机会帮助您。
  • 检查您是否在 viewWillLayoutSubviews 中呈现场景 - 如果是,则知道此方法将在每次视图调整大小或旋转时再次运行

标签: objective-c sprite-kit skscene


【解决方案1】:

[[NSNotificationCenter defaultCenter] postNotificationName:@"closeScene" object:nil];

这就是问题所在。我只是在其他场景之上呈现场景。需要通过发布通知从层次结构中删除场景。问题解决了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多