【发布时间】:2017-02-06 23:26:35
【问题描述】:
我正在学习 Swift 和 SpriteKit,目前面临一个问题。基本上我正在尝试将可点击的 SKSpriteNode 实现为“返回菜单”并重置游戏。 到目前为止我的代码: 在 GameScene.swift
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
//let node = self.nodes(at: location)
let node : SKNode = self.atPoint(location)
if node.name == "back_button" {
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = mainStoryboard.instantiateViewController(withIdentifier: "MenuVC_ID")
gameVC?.dismiss(animated: true, completion: nil)
self.view?.window?.rootViewController?.present(vc, animated:true, completion: nil)
self.view?.presentScene(nil)
}
}
}
MenuVC.swift
class MenuVC : UIViewController {
@IBAction func Player2(_ sender: Any) {
moveToGame(game: gameType.player2)
}
@IBAction func easy(_ sender: Any) {
moveToGame(game: gameType.easy)
}
@IBAction func medium(_ sender: Any) {
moveToGame(game: gameType.medium)
}
@IBAction func hard(_ sender: Any) {
moveToGame(game: gameType.hard)
}
override func viewDidLoad() {
super.viewDidLoad()
print ("somtu")
}
func moveToGame(game: gameType) {
print("movetogame")
let gameVC = self.storyboard?.instantiateViewController(withIdentifier: "gameVC") as! GameViewController
currentGameType = game
self.navigationController?.pushViewController(gameVC, animated: true)
}
每当我在游戏中点击back_button 时,MenuVC 就会出现,但在按钮点击时什么也没有发生。我尝试了其他帖子中的几个建议,但没有一个能正常工作。
谢谢你的回答。
【问题讨论】:
标签: swift uiviewcontroller sprite-kit skspritenode