热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

标识同一位置的所有节点-Identifyallnodesatsamelocation

IhaveaiOSappthatdrawsagridofspritesonscreen.Ithenhaveanotherspriterepresentingac

I have a iOS app that draws a grid of sprites on screen. I then have another sprite representing a colour which I can drag and drop over the grid. My question is how do I identify which sprite on the grid it was dragged onto?

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

Ultimately I want to allow a user to drag a colour sprite over another sprite, so I can change the colour, as per the users selection.

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

The code below only returns the 2nd sprite (the top one) at the location, whereas I need to identify both sprites at that location.

下面的代码只返回位置上的第二个sprite(顶部),而我需要在那个位置识别两个精灵。

 override func touchesEnded(touches: Set, 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)")


    }
}

1 个解决方案

#1


2  

 override func touchesEnded(touches: Set, 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)")

        }
    }
}

推荐阅读
author-avatar
一颗顽石
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有