我有一个SKSpriteNode,其纹理分配如下:
node.texture = SKTexture(imageNamed: "Oval")
用户可以选择此对象并将其拖动。我使用以下内容来确定何时在 touchesMoved 函数中选择它。
var touchedNode = allObjects.nodeAtPoint(location)
问题是此图像文件的表面区域几乎一半是透明的。但是, nodeAtPoint 会对透明度的触摸做出响应。
有没有人知道忽视透明度的方法?
答案 0 :(得分:1)
在触摸中移动您可以获得所触摸节点像素的颜色,然后使用if语句,如果颜色是透明的,则可以忽略该节点(alpha为0)。点击此处查看如何获取颜色
SpriteKit: How can I get the pixel color from a point in SKSpriteNode?