【问题标题】:determine the name of the sprite by position通过位置确定精灵的名称
【发布时间】:2018-05-19 17:06:53
【问题描述】:

我有很多SpriteNode:

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

其中一个有一个职位,例如:

CGPoint(x: 1159, y: 406)

如何找出处于这个位置的精灵的名字?

【问题讨论】:

    标签: ios swift sprite-kit skspritenode


    【解决方案1】:

    如果您只有坐标,您可以尝试: 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
         }
     }
    

    【讨论】:

    • nodeAtPoint 返回与点相交的最深可见后代。"background"
    • 不客气。很高兴听到!请随时投票并接受答案。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多