How to draw a line in Sprite-kit

前端 未结 7 1104
长发绾君心
长发绾君心 2020-12-02 18:09

How can one draw a line in Sprite-kit? For example if I want to draw a line in cocos2d, I could easily using ccDrawLine();

Is there an equivalent in sp

7条回答
  •  悲&欢浪女
    2020-12-02 19:05

    Here is my Swift 4 function to add a Line between two points:

    func drawLine(from: CGPoint, to: CGPoint) {
        let line = SKShapeNode()
        let path = CGMutablePath()
        path.addLines(between: [from, to])
        line.path = path
        line.strokeColor = .black
        line.lineWidth = 2
        addChild(line)
    }
    

    Hope it helps!!

提交回复
热议问题