I´m new to coding and I created a game with two scenes(Game Scene and Main menu) with Sprite-Kit. I have a Home Button which switches back to the Main Menu Scene from the Game Scene. When I tapp on the Home Button the app crashes and I wasn´t able to find a solution yet.
Here is the error(occurs while running 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
This is my code:
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
}