【问题标题】:Identify all nodes at same location识别同一位置的所有节点
【发布时间】:2016-02-09 11:49:08
【问题描述】:

我有一个在屏幕上绘制精灵网格的 iOS 应用程序。然后我有另一个精灵代表一种颜色,我可以将它拖放到网格上。我的问题是如何识别它被拖到网格上的哪个精灵?

最终我希望允许用户将一个颜色精灵拖到另一个精灵上,这样我就可以根据用户的选择更改颜色。

下面的代码只返回该位置的第二个精灵(最上面的一个),而我需要识别该位置的两个精灵。

 override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?)
{
    print("tocuhes ended")

    for touch in touches
    {
        let location = touch.locationInNode(self)
        let nodeAtLocation = self.nodeAtPoint(location)

        let nodeName = nodeAtLocation.name

        print("Node Name \(nodeName)")


    }
}

【问题讨论】:

标签: ios iphone swift sprite-kit ios9


【解决方案1】:
 override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {

    for touch in touches
    {
        let location = touch.locationInNode(self)
        let nodesAtLocation = self.nodesAtPoint(location)

        for node in nodesAtLocation {

            let nodeName = node.name

            print("Node Name \(nodeName)")

        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多