gpt4 book ai didi

ios - 除非模拟器是 XS 品种,否则屏幕上的按钮不起作用

转载 作者:行者123 更新时间:2023-11-28 11:40:01 26 4
gpt4 key购买 nike

基本上我的应用程序运行良好,但是当我尝试在除 Xcode 中的 XS 模拟器以外的任何其他模拟器上运行它时,主菜单按钮不再工作,我不知道在哪里寻找错误,因为什么都没有抛出任何错误。此外,当我将打印语句放入节点内时,打印语句会打印到控制台,告诉我屏幕正在检测选择,但由于某种原因代码无法运行。这很奇怪,因为它是被调用函数中的一个简单的 if else 语句,所以我认为没有理由它不应该运行。

 var background = SKSpriteNode(imageNamed: "bgImage")
var newGameButtonNode:SKSpriteNode!
var difficultyButtonNode:SKSpriteNode!
var difficultyLabelNode:SKLabelNode!
var gameModeNode:SKSpriteNode!
var gameModeLabel:SKLabelNode!
var gameMode:Int = 1


override func didMove(to view: SKView) {

background.zPosition = -4
background.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
background.scale(to: (self.scene?.size)!)
addChild(background)
newGameButtonNode = self.childNode(withName: "newGame") as? SKSpriteNode
difficultyButtonNode = self.childNode(withName: "difficultyButton") as? SKSpriteNode
difficultyLabelNode = self.childNode(withName: "difficultyLabel") as? SKLabelNode
gameModeNode = SKSpriteNode(imageNamed: "toggle")
gameModeLabel = self.childNode(withName: "gameModeLabel") as! SKLabelNode

let userDefaults = UserDefaults.standard
if userDefaults.bool(forKey: "hard") {
difficultyLabelNode.text = "HARD MODE"
} else {
difficultyLabelNode.text = "EASY MODE"
}
gameMode = userDefaults.integer(forKey: "mode")
if gameMode == 1{
gameModeLabel.text = "Crypto Catch"
userDefaults.set(1, forKey: "mode")
} else if gameMode == 2 {
gameModeLabel.text = "Crypto Invaders"
userDefaults.set(2, forKey: "mode")
} else if gameMode == 3 {
gameModeLabel.text = "Crypto Galiga"
userDefaults.set(3, forKey: "mode")
}

difficultyButtonNode.texture = SKTexture(imageNamed: "toggleYellow")
difficultyButtonNode.anchorPoint = CGPoint(x: 0, y: 0)
difficultyButtonNode.scale(to: CGSize(width: 250 , height: 250))
newGameButtonNode.texture = SKTexture(imageNamed:"playGameYellow")
newGameButtonNode.anchorPoint = CGPoint(x: 0, y: 0)
gameModeNode.anchorPoint = CGPoint(x: 0, y: 0)
gameModeNode.scale(to: CGSize(width: 250, height: 250))
gameModeNode.name = "gameModeNode"
newGameButtonNode.scale(to: CGSize(width: 250, height: 250))
difficultyButtonNode.position = CGPoint(x: (scene?.size.width)!/2-125, y: (scene?.size.height)!/2-150)
newGameButtonNode.position = CGPoint(x: (scene?.size.width)!/2-125, y: (scene?.size.height)!/2+150)
difficultyLabelNode.position = CGPoint(x: (scene?.size.width)!/2, y: (scene?.size.height)!/2-175)
gameModeLabel.position = CGPoint(x: (scene?.size.width)!/2, y: (scene?.size.height)!/2-175 - 300)
self.addChild(gameModeNode)
gameModeNode.position = CGPoint(x: (scene?.size.width)!/2-125, y: (scene?.size.height)!/2-175 - 250)


}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
if let location = touch?.location(in: self){
let nodesArray = self.nodes(at: location)
if nodesArray.first?.name == "newGame"{
if gameMode == 1{
let transition = SKTransition.flipHorizontal(withDuration: 0.5)
let gameSceneOB = GameScene(fileNamed: "GameScene")
gameSceneOB?.scaleMode = .aspectFill

self.view?.presentScene(gameSceneOB!, transition: transition)
} else if gameMode == 2 {
let transition = SKTransition.flipHorizontal(withDuration: 0.5)
let gameSceneOB = GameScene(fileNamed: "ShooterGame")
gameSceneOB?.scaleMode = .aspectFill

self.view?.presentScene(gameSceneOB!, transition: transition)

} else if gameMode == 3 {
let transition = SKTransition.flipHorizontal(withDuration: 0.5)
let gameSceneOB = GameScene(fileNamed: "cryptoGal")
gameSceneOB?.scaleMode = .aspectFill

self.view?.presentScene(gameSceneOB!, transition: transition)

}

} else if nodesArray.first?.name == "difficultyButton" {
changeDifficulty()
} else if nodesArray.first?.name == "gameModeNode"{
toggleGameMode()

}
}
}
func changeDifficulty() {
let userDefaults = UserDefaults.standard
if difficultyLabelNode.text == "EASY MODE"{
difficultyLabelNode.text = "HARD MODE"
userDefaults.set(true, forKey: "hard")
} else {
difficultyLabelNode.text = "EASY MODE"
userDefaults.set(false, forKey: "hard")
}
userDefaults.synchronize()
}
func changeGameMode() {
let userDefaults = UserDefaults.standard
if gameMode == 1{
gameModeLabel.text = "Crypto Catch"
userDefaults.set(1, forKey: "mode")
} else if gameMode == 2 {
gameModeLabel.text = "Crypto Invaders"
userDefaults.set(2, forKey: "mode")
} else if gameMode == 3 {
gameModeLabel.text = "Crypto Galiga"
userDefaults.set(3, forKey: "mode")
}
userDefaults.synchronize()
}
func toggleGameMode(){
if gameMode == 1{
gameMode = 2
} else if gameMode == 2 {
gameMode = 3
} else if gameMode == 3 {
gameMode = 1
}
changeGameMode()
}

最佳答案

一般来说,spriteKit/Metal 等在模拟器中是行不通的!

您必须构建到手机上!

它可能只是在新的 XS 模拟器中“巧合”地工作。仅此而已。仅针对手机构建。

关于ios - 除非模拟器是 XS 品种,否则屏幕上的按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53936297/

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