1

i've got a little problem with my spritkit game. I have created a little Jump N Run game where a penguin must dodge as icebergs or you can also collect fish. As a penguin you have three lives. Are these lives now in the end because you were already met three times of icebergs, I want that one will be automatically redirected to a new UIViewController by then finally can perform new actions. I have everything created with xib files and now just do not know how I made ​​the skscene back to a UIViewController gelange ...

Would be great if someone could help me. :)

Sport
  • 8,570
  • 6
  • 46
  • 65
  • might help this: http://stackoverflow.com/questions/19142632/how-to-perform-segue-from-within-a-skscene-layer-spritekit – nzs Jan 06 '14 at 14:35

1 Answers1

1

The most clean solution is to declare and implement a protocol to let the UIViewController know that it should react to a change in SKScene.

@protocol MySceneDelegate <NSObject>
- (void)closeScene;
@end

@interface MyScene : SKScene
@property(nonatomic, strong) SKShapeNode *ball;
@property (weak) id <MySceneDelegate> delegate;
@end

View controller that shows the scene should implement a closeScene method and set itself as a delegate of the scene. Example:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure the view.
    SKView * skView = (SKView *)self.view;
    skView.showsFPS = YES;
    skView.showsNodeCount = YES;

    // Create and configure the scene.
    MyScene * scene = [MyScene sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;

    // Set the delegate
    [scene setDelegate:self];

    // Present the scene.
    [skView presentScene:scene];
}

Then in the scene you can call the closeScene method of the view controller which was set as a delegate:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    /* Called when a touch begins */

    if ([_delegate respondsToSelector:@selector(closeScene)])
    {
        [_delegate performSelector:@selector(closeScene)];
    }
}

Hope it helps.

Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143