我知道这个问题已被多次询问,但大多数都没有得到妥善回答,也没有像我一样遵循相同的设置。
我有两个GameViewController
,MenuViewController
和MenuViewController。 UIKit
使用了故事板和GameViewController
。 SKScene
加载MenuViewController
。当应用启动时,会打开GameViewController
。我已经制作了一个按钮,可以在故事中按菜单上的游戏进行操作。这是有效的,但现在我正在尝试相反的做法,并在游戏中返回菜单。我试图使用已回答类似问题的代码,但似乎都没有。
这是我用class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let view = self.view as! SKView?{
if let scene = SKScene(fileNamed: "GameScene"){
let gameScene = scene as! GameScene
gameScene.gameViewControllerDelegate = self
gameScene.scaleMode = .aspectFill
view.presentScene(gameScene)
}
view.showsFPS = true
view.showsNodeCount = true
view.ignoresSiblingOrder = true
// Do any additional setup aft)er loading the view.
}
}
func callMethod(inputProperty:String){
print("inputProperty is: ",inputProperty)
}
搞砸的:
class GameScene: SKScene, SKPhysicsContactDelegate {
weak var gameViewControllerDelegate:GameViewControllerDelegate?
override func didMove(to view: SKView) {
gameViewControllerDelegate?.callMethod(inputProperty: "call game view controller method")
我添加到GameScene的代码:
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String token = ((OAuth2AuthenticationDetails) authentication.getDetails()).getTokenValue();