Pracuję w Swift z zestawem Sprite za pomocą XCode 6 i mam wiele różnych węzłów, ale na razie tylko uda mi się wykryć tylko jeden palec i przesuwać jeden węzeł w tym samym czasie. Chcę wiedzieć, w jaki sposób udało mi się wykryć wiele palców, aby przesuwać wiele węzłów w tym samym czasie. Moje rzeczywisty kod jest:Gesty wielodotykowe w zestawie Sprite
var location = CGFloat() // finger position
var actualNode = -1 // node touched by the finger, -1 means no node touched
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) // when a finger touch the screen
{
for touch: AnyObject in touches
{
location = touch.locationInNode(self) // we detect the finger position
}
for var index = 0; index < colorNode.count; index++
{
if nodeAtPoint(location) == colorNode[index].node
{
actualNode = index // the number of the node touched by the finger
}
}
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) // when a finger move
{
for touch: AnyObject in touches
{
location = touch.locationInNode(self) // we detect the finger position
}
if actualNode != -1 // if a node is touched
{
colorNode[actualNode].position = location // we move this node to the finger
}
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) // when a finger don't touch the screen anymore
{
actualNode = -1 // there is no node touched
}
Jak widać mam tylko position
mojego pierwszego palca, ale w jaki sposób można wykryć wiele pozycji palca i przypisać każdy palec do węzła dotknął palcem?
Dzięki. To działa dobrze. – Epsilon