0

I don't understand why my doesn't work.

Use case :

  1. Test 1: I launch game, i click on Play button (presentScene) from the first Scene, So i go to second scene. No problem.
  2. Test 2: I launch game, i click on Option button (presentViewController) from the first Scene. On Optin controller, i click to dismissViewControllerAnimated. If i want click on Play button, there is no change on screen but the game is plain behind. I don't understand why the scene stay on screen and why there is no transition.

There is no error output.

Code Controller:

- (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;
        }
    }
}
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Alexandre Ouicher
  • 856
  • 1
  • 9
  • 15
  • Check that self.view.window.rootViewController is really the controller you want to dismiss. Verify that viewDidLoad does not get called a second time, if so, it would indicate that a new SKView was created. Check for memory leaks respectively objects not deallocating where they should, specifically SK view controller. The problem sounds as if you create a 2nd SKView while the original SKView is still in memory. – CodeSmile Mar 18 '14 at 11:24
  • I have added a breakpoint after viewDidLoad but there is called only one time. – Alexandre Ouicher Mar 18 '14 at 11:33

1 Answers1

0

Now it's OK!

I have replaced notification with a call from the Menu Scene:

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

With that, i can find the original controller after completion.

Alexandre Ouicher
  • 856
  • 1
  • 9
  • 15