作者:那0年_277 | 来源:互联网 | 2023-05-19 09:51
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 个解决方案