【发布时间】:2017-03-03 17:33:50
【问题描述】:
我想在SKScene 中清理我的touchesBegan(..)。我想做一个案例陈述而不是我的if .. else 链。但是,我在实施时遇到错误,这表明我不知道平等是如何在幕后完成的。
代码前:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
if self.nodeAtPoint(location) === playLabel {
buildLevelSelect()
} else if self.nodeAtPoint(location) === aboutLabel {
createAboutView()
} else if self.nodeAtPoint(location) === storeLabel {
createStore()
}
}
}
代码后:点击后,一些标签点击工作,但其他一些引发Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode 0x0)错误:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
switch(self.nodeAtPoint(location)){
case playLabel :
buildLevelSelect()
case aboutLabel :
createAboutView()
case storeLabel :
createStore()
default : break
}
}
【问题讨论】:
标签: ios swift sprite-kit switch-statement skscene