gpt4 book ai didi

ios - 在 iOS 中点击标签后是否可以更改场景?

转载 作者:搜寻专家 更新时间:2023-11-01 07:11:47 24 4
gpt4 key购买 nike

我有一个学校项目来制作一款运行良好的游戏,但我正在努力添加后退按钮。我想点击“返回”一词将您带到菜单,但我不知道该怎么做。正常的“按钮”不可用,因为它要从 sprite 套件场景返回。任何建议或帮助表示赞赏。

最佳答案

给你:

菜单VC.swift:

enum gameType {
case easy
case wobble
case player2
}

var currentGameType: gameType = .easy
var navController = UINavigationController()
var storyBoard = UIStoryboard()

func presentMenuVC() {
let menuVC = storyBoard.instantiateViewController(withIdentifier: "menuVC") as! MenuVC
navController.pushViewController(menuVC, animated: true)
}

class MenuVC : UIViewController {

@IBAction func Player2(_ sender: Any) {
moveToGame(game: .player2)
}
@IBAction func Easy(_ sender: Any) {
moveToGame(game: .easy)
}
@IBAction func Wobble(_ sender: Any) {
moveToGame(game: .wobble)
}

func moveToGame(game: gameType) {

navController = self.navigationController!
storyBoard = self.storyboard!

let gameVC = self.storyboard?.instantiateViewController(withIdentifier: "gameVC") as! GameViewController

currentGameType = game

self.navigationController?.pushViewController(gameVC, animated: true)

}
}

新文件.swift:

class MainMenuButton: SKSpriteNode {

init(text: String, font: String) {
let label = SKLabelNode(text: text)
label.fontName = font

let texture = SKView().texture(from: label)

super.init(texture: texture!, color: .clear, size: texture!.size())
isUserInteractionEnabled = true
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
presentMenuVC()
}

required init?(coder aDecoder: NSCoder) { fatalError() }
}

GameScene.swift(添加到底​​部的 didMoveToView 函数):

addChild(MainMenuButton(text: "go back", font: "Chalkduster"))

关于ios - 在 iOS 中点击标签后是否可以更改场景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44501826/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com