【发布时间】:2017-11-12 11:30:08
【问题描述】:
我是编码新手,我使用 Sprite-Kit 创建了一个包含两个场景(游戏场景和主菜单)的游戏。我有一个主页按钮,可以从游戏场景切换回主菜单场景。当我点击主页按钮时,应用程序崩溃了,我还没有找到解决方案。
这是错误(在运行 touchesEnded() 时发生):
libc++abi.dylib: terminating with uncaught exception of type NSException
libsystem_kernel.dylib`__pthread_kill:
0x112417d38 <+0>: movl $0x2000148, %eax ; imm = 0x2000148
0x112417d3d <+5>: movq %rcx, %r10
0x112417d40 <+8>: syscall
-> 0x112417d42 <+10>: jae 0x112417d4c ; <+20>
0x112417d44 <+12>: movq %rax, %rdi
0x112417d47 <+15>: jmp 0x112410caf ; cerror_nocancel
0x112417d4c <+20>: retq
0x112417d4d <+21>: nop
0x112417d4e <+22>: nop
0x112417d4f <+23>: nop
这是我的代码:
var homeButton = SKSpriteNode(imageNamed: "HomeButton5.0")
class GameScene{
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches{
let locationUser = touch.location(in: self)
if atPoint(locationUser) == homeButton {
}
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches{
let locationUser = touch.location(in: self)
if atPoint(locationUser) == homeButton { // <-- error/ crash
let transition = SKTransition.crossFade(withDuration: 0.2)
let mainMenu = Mainmenu(size: self.size)
self.view?.presentScene(mainMenu, transition: transition) //transition
}
}
}
}
class Mainmenu: SKScene{ //Scene to switch to
}
【问题讨论】:
-
请正确格式化您的代码并使用缩进,没有缩进很难阅读您的代码,这不是您第一个缺少正确格式的问题。
-
但我正在使用 Sprite-Kit @AndersSørensen
-
尝试使用:let homeButton = SKSpriteNode(imageNamed: "HomeButton5.0")
-
那行不通。 @AndersSørensen
标签: swift button sprite-kit runtime-error transition