How do I go from SKScene to UIViewController by code?

前端 未结 3 1551
盖世英雄少女心
盖世英雄少女心 2020-11-30 08:24

All I want if for when the user touches a skspritenode in the skscene, it will go to a different view like performseguewithidentifier. Thanks for any help. I ca

3条回答
  •  无人及你
    2020-11-30 09:02

    ZeMoon, nice answer, but what if multiple scenes want to show the same view controller, for example some settings screen? You don't want to define multiple scene delegate protocols that do the same thing.

    Another idea is to define a single protocol which handles the presentation of different view controllers for you:

    @protocol ScreenFlowController 
    - (void)presentSettingsScreenFromScene:(SKScene *)scene;
    - (void)presentCreditsScreenFromScene:(SKScene *)scene;
    @end
    

    The scene parameter might be used to make decisions based on where you are coming from.

    The view controller of your game (or any other object) implements the protocol. All scenes that display a different screen receive a weak reference to the controller:

    @property (nonatomic, weak) id screenFlowController;
    

提交回复
热议问题