我想确定从某个点开始在某个方向上是否有节点。
到目前为止,我尝试了enumerateBodies
的Swift功能,但似乎无法识别某些光线上的节点
var block1 = SKShapeNode(rectOf: CGSize(width: 300, height: 100))
var block2 = SKShapeNode(rectOf: CGSize(width: 300, height: 100))
let rayStart = CGPoint(x: 2800, y: 400)
let rayEnd = CGPoint(x: 3100, y: 400 )
block1.fillColor = SKColor.white
block2.fillColor = SKColor.red
block1.position = CGPoint(x:3000,y:400)
block2.position = CGPoint(x:2900,y:400)
self.addChild(block1)
self.addChild(block2)
self.physicsWorld.enumerateBodies(alongRayStart: rayStart, end:
rayEnd) {(body, point, vector, stop) in
print("here")
}
我希望在控制台中看到“ here”字样,但enumerateBodies内部的块甚至无法工作。我在做什么错了?