按位置确定精灵的名称

determine the name of the sprite by position

我有很多SpriteNode:

sharesA.name = "sharesA"
sharesB.name = "sharesB"
sharesC.name = "sharesC"
ect.....

其中一位有职位举例:

CGPoint(x: 1159, y: 406)

如何找出该位置的精灵名称?

如果您只有坐标可以尝试: let name = nodeAtPoint(location).name ?? ""

如果你想根据用户的触摸来判断,你可以尝试这样的方法:

 class MyScene: SKScene {

     override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

        var touch = touches as!  Set<UITouch>
        var location = touch.first!.locationInNode(self)
        var node = self.nodeAtPoint(location)
        let nodeName = node.name
     }
 }