我试图了解如何在触摸时创建SKShapeNode线并使终点跟随触摸。我已经弄清楚如何反复创建线,但不是根据当前触摸位置实际动态地改变其终点。有谁知道如何做到这一点?谢谢。 这是我目前的代码:
func touchDown(atPoint pos : CGPoint) {
if captain.contains(pos){
selectedUnit = "p1"
}
}
func touchMoved(toPoint pos : CGPoint) {
if selectedUnit == "p1" {
let line = SKShapeNode()
startPoint = CGPoint(x:captain.position.x,y:captain.position.y)
endPoint = pos
pathToDraw.move(to: CGPoint(x: startPoint.x, y: startPoint.y))
// pathToDraw.addLine(to: CGPoint(x: endPoint.x, y: endPoint.y))
pathToDraw.addLine(to: CGPoint(x: pos.x, y: pos.y))
line.zPosition = 100
line.path = pathToDraw
line.strokeColor = UIColor.red
line.lineWidth = 5
self.addChild(line)
}
}