在presentViewController之后,SKScene重复

时间:2014-03-18 10:26:46

标签: objective-c sprite-kit skscene

我不明白为什么我不行。

用例:

  1. 测试1:我启动游戏,我从第一个场景点击播放按钮(presentScene),所以我去了第二个场景。没问题。
  2. 测试2:我启动游戏,然后从第一个场景中单击“选项”按钮(presentViewController)。在Optin控制器上,我点击解除ViewControllerAnimated。如果我想点击“播放”按钮,屏幕上没有任何变化,但游戏很明显。我不明白为什么场景会留在屏幕上以及为什么没有过渡。
  3. 没有错误输出。

    代码控制器:

    - (void)viewDidLoad
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showParam) name:kNotificationShowParam object:nil];
        //...
        SKView * skView = (SKView *)self.view;
        SKScene * scene = [[MenuScene alloc ]initWithSize:skView.bounds.size];
        scene.scaleMode = SKSceneScaleModeAspectFill;
        [skView presentScene:scene];
    }
    
    - (void)showParam
    {
        ParamViewController *ParamView = [[crazyButterflyParamViewController alloc]init];
        [self presentViewController: ParamView animated: YES completion:^ {
        }];
    }
    

    Code ParamController:

    //method on button
    -(void)goToMenu
    {
        [self.view.window.rootViewController dismissViewControllerAnimated:YES completion:^{
        }];
    }
    

    Code MenuScene:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        for (UITouch* touch in touches)
        {
            if ([_button containsPoint:[touch locationInNode:_button.parent]])
            {
                SKTransition *transition = [SKTransition fadeWithDuration:0.4];
                SKScene *scene = [[GameScene alloc] initWithSize:self.size];
                scene.scaleMode = SKSceneScaleModeAspectFill;
                [self.scene.view presentScene:scene transition:transition];
                break;
            }
    
    
            if ([_buttonParam containsPoint:[touch locationInNode:_buttonParam.parent]])
            {
                [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationShowParam object:nil];
                break;
            }
        }
    }
    

1 个答案:

答案 0 :(得分:0)

现在好了!

我已通过菜单场景中的调用替换了通知:

if ([_buttonParam containsPoint:[touch locationInNode:_buttonParam.parent]])
    {
        //[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationShowParam object:nil];
        [self.view.window.rootViewController presentViewController:_paramController animated: YES completion:^(void) {
            SKView * skView = (SKView *)self.view;
            MyScene *MenuScene = [[MyScene alloc]initWithSize:skView.bounds.size];
            MenuScene.scaleMode = SKSceneScaleModeAspectFill;
            [skView presentScene:MenuScene];
        }];
        break;
    }

有了这个,我可以在完成后找到原始控制器。