我需要从SpriteKit GameViewController转换到iOS应用程序中的常规View Controller(Objective-C)

时间:2023-01-22 23:03:24

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:

我正在使用SpriteKit在Objective-C中制作游戏,但也有一些视图控制器。我只需按一下按钮就可以从SpriteKit场景转换到非SpriteKit视图控制器。该按钮只是一个SpriteKit节点,可以使用以下代码按下:

-(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.

现在,我不太清楚在if语句中放入什么,以确定是否按下了后退按钮。我不知道,虽然我试过这个。任何帮助,将不胜感激。

1 个解决方案

#1


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:

好吧,实现它的一种方法是使用main.storyboard。您是否尝试过以这种方式设置两个视图控制器?如果这不起作用,请告诉我:

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.

您实际上可以使用“Sprite Kit View Controller”和“View Controller”来适应您的游戏。使用故事板设置场景转换按钮,并使用代码适应游戏的其余部分。按钮将卡在那里,所以把它放在一个好地方。

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

只需在按钮和“视图控制器”之间设置一个过渡,就像在任何单视图应用程序中一样。

#1


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:

好吧,实现它的一种方法是使用main.storyboard。您是否尝试过以这种方式设置两个视图控制器?如果这不起作用,请告诉我:

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.

您实际上可以使用“Sprite Kit View Controller”和“View Controller”来适应您的游戏。使用故事板设置场景转换按钮,并使用代码适应游戏的其余部分。按钮将卡在那里,所以把它放在一个好地方。

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

只需在按钮和“视图控制器”之间设置一个过渡,就像在任何单视图应用程序中一样。