Your scene needs to offer a line of communication to your controller to indicate that is finished. You could, for example, create a delegate protocol and corresponding property in your scene. An example:
@protocol TCAMySceneDelegate;
@interface TCAMyScene : SKScene
@property (nonatomic, weak> id<TCAMySceneDelegate> delegate;
@end
@protocol TCAMySceneDelegate <NSObject>
- (void)mySceneDidFinish:(TCAMyScene *)gameScene;
@end
Then, in the .m of your TCAMyScene
- (void)endTheGame {
// Other game-ending code
[self.delegate mySceneDidFinish:self];
}
In your view controller, set itself as the delegate for your scene and implement the method:
- (IBAction)startGame:(id)sender {
// Other code
TCAMyScene *theScene = [TCAMyScene sceneWithSize:skView.bounds.size];
theScene.scaleMode = SKSceneScaleModeAspectFill;
theScene.delegate = self;
// Other code
}
- (void)mySceneDidFinish:(TCAMyScene *)myScene {
// logic for dismissing the view controller
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…