Tôi đang làm việc với Swift với Sprite-Kit sử dụng XCode 6 và tôi có nhiều nút khác nhau nhưng hiện tại tôi chỉ phát hiện một ngón tay và di chuyển một nút cùng một lúc. Tôi muốn biết làm thế nào tôi có thể quản lý để phát hiện nhiều ngón tay để di chuyển nhiều nút cùng một lúc. mã thực tế của tôi là:Cử chỉ cảm ứng đa điểm trong Sprite Kit
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
}
Như bạn có thể thấy tôi chỉ có position
của ngón tay đầu tiên của tôi, nhưng làm thế nào tôi có thể phát hiện nhiều vị trí ngón tay và gán mỗi ngón tay đến nút chạm bằng ngón tay?
Cảm ơn. Điều này hoạt động tốt. – Epsilon