- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
基本上我的应用程序运行良好,但是当我尝试在除 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/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!