我只是想知道如何從場景中移除SKSprite節點。這是我到目前爲止有:Swift + Sprite套件觸摸檢測
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = (touch as UITouch).locationInNode(self)
if let theName = self.nodeAtPoint(location).name {
if theName == "monster" {
monster! .removeFromParent()
}
}
}
}
我創造很多在屏幕上這些怪物的,但是當我在其中一人挖掘它不會做任何事情。如果我嘗試添加println("touched")
,它告訴我它已被觸動。
您是否給每個怪物命名爲「怪物」?你有沒有在所有的怪物上設置userInteractionEnabled爲true? – Okapi