JustMe
JustMe

Reputation: 316

I need to transition from a SpriteKit GameViewController to a regular View Controller in an iOS app (Objective-C)

I am making a game in Objective-C using SpriteKit, but there are also some view controllers. I need to transition from a SpriteKit scene to the non-SpriteKit view controller at a push of a button. The button is simply made of a SpriteKit Node, and can be pressed using this code:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInNode:self];
    SKNode *node = [self nodeAtPoint:location];

    //if back button touched, show other view
    if ([node.name isEqualToString:@"backbutton"]) {
        //transition code goes here
    }
}

Now, I'm not quite sure what to put in the if statement that figures out if the back button is pressed. I have no idea, though I tried this. Any help would be appreciated.

Upvotes: 0

Views: 345

Answers (1)

Christian Kreiter
Christian Kreiter

Reputation: 620

Well, one way of going about it would be to use the main.storyboard, actually. Have you tried setting up both view controllers that way? Let me know if this doesn't work:

You can actually use an 'Sprite Kit View Controller' and a 'View Controller' to fit your game. Set up the scene-transitioning button using the storyboard, and fit the rest of the game by using code. The button will be stuck there, so put it in a good place.

Merely set up a transition between the button and the 'View Controller' like you would in any Single View Application.

Upvotes: 1

Related Questions