Xcode 他很快就犯了错误
我试图在Swift中重载touchesBegind函数,但我遇到了一个奇怪的错误,导致XCode崩溃 我认为问题出在第“Xcode 他很快就犯了错误,xcode,swift,touchesbegan,Xcode,Swift,Touchesbegan,我试图在Swift中重载touchesBegind函数,但我遇到了一个奇怪的错误,导致XCode崩溃 我认为问题出在第“行touch:anyobjectintouch{”中,但我在其他类中使用了它,它工作得非常好 这是我的代码: import SpriteKit class PlayScene: SKScene { let touchButton = SKSpriteNode(imageNamed:"Touch") override func didMoveToView(vi
行touch:anyobjectintouch{
”中,但我在其他类中使用了它,它工作得非常好
这是我的代码:
import SpriteKit
class PlayScene: SKScene {
let touchButton = SKSpriteNode(imageNamed:"Touch")
override func didMoveToView(view: SKView!) {
self.backgroundColor = UIColor(hex: 0xD64541)
self.touchButton.size = CGSizeMake(50, 50)
let touchButtonWidth = self.touchButton.size.width
let touchButtonHeight = self.touchButton.size.height
self.touchButton.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
self.addChild(self.touchButton)
}
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
if self.nodeAtPoint(location) == self.touchButton {
println("button")
}
else {
println("ext")
}
}
}
}
谢谢在迭代之前尝试检查
触摸
是否为零(对我有效):
它有效!事实上我真的不明白为什么我的方法无效。谢谢!
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
if let tchs = touches {
for touch: AnyObject in tchs {
let location = touch.locationInNode(self)
if self.nodeAtPoint(location) == self.touchButton {
println("button")
}
else {
println("ext")
}
}
}
}