0
我知道這可能以前曾被問過,但沒有什麼正是我需要的。現在想象一下這種情況,我有一個遊戲,在這個遊戲中,屏幕中間有一個名爲Background的SKSpriteNode。在那個背景上,Sprite有一個叫做Button的小孩。如何檢測按鈕上的觸摸是否已結束。如果有人能夠幫助我使用TouchesEnded函數的代碼,並且可能會更詳細地解釋發生了什麼。謝謝你,swift會是理想的,但我想如果需要的話我可以閱讀Objective-C。如何檢測一個孩子精靈的觸摸
ADDED信息
這裏是我的兩個精靈:
let buttonBackground = SKSpriteNode(imageNamed: "Button Background.png") //The parent node of button
let soundOn = SKSpriteNode(imageNamed: "Sound On.png") //The button being pressed, which is a child of buttonBackground
這裏是我的touchesEnded功能:
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
// Called when a touch begins
for touch in touches {
let location = touch.locationInNode(self)
let nodeAtTouch = self.nodeAtPoint(location)
let touchedSprite = nodeAtTouch as! SKSpriteNode
if touchedSprite == button {
print("YES")
}
}
}
skNode是您從觸摸中檢索到的SKSpriteNode。請顯示您的碰撞如何工作的一些代碼。如果您對此不熟悉,請查看:http://www.techotopia.com/index.php/A_Swift_iOS_8_Sprite_Kit_Collision_Handling_Tutorial – penatheboss
我的錯我的意思是一個聲明,顯示是否觸摸skNode時 – grahamcracker1234
skNode是節點被觸摸...每當觸摸發生時skNode是被觸摸的節點 – penatheboss