用底线绘制半圆圈将其用作SpriteKit中的Skshapenode

发布于 2025-01-21 19:13:24 字数 916 浏览 4 评论 0原文

我想用底线绘制一个半圆圈,然后再次将其重用为形状节点。我该如何实施。这是我的半圈代码。 而且对某些代码进行了硬编码,因此对一些帮助表示赞赏。

func drawLine(from: CGPoint, to: CGPoint) {
// for line
    let myLine = SKShapeNode()
    let myPath = CGMutablePath()
    myPath.addLines(between: [from, to])
    myLine.path = myPath
    myLine.strokeColor = SKColor.blue
    myLine.lineWidth = 4
    addChild(myLine)
}
func drawSemi(){
// for semi circle

    let bezierPath = UIBezierPath(arcCenter: CGPoint(x: 0, y: 0), radius: 50, startAngle: 0, endAngle: .pi, clockwise: true)
    
    let pathNode = SKShapeNode(path: bezierPath.cgPath)
    
    pathNode.strokeColor = SKColor.blue
    
    pathNode.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
    
    
    pathNode.lineWidth = 3
    
    
    
    addChild(pathNode)
}
func drawCompleteSemi(){
    drawSemi()
    drawLine(from: CGPoint(x: 450, y: 500), to: CGPoint(x: 550, y: 500))
}

I want to draw a semi circle with the bottom line and reuse it as shape node again. How can I implement this. This is my code for semi circle.
And also some code is hard coded so some help is appreciated.

func drawLine(from: CGPoint, to: CGPoint) {
// for line
    let myLine = SKShapeNode()
    let myPath = CGMutablePath()
    myPath.addLines(between: [from, to])
    myLine.path = myPath
    myLine.strokeColor = SKColor.blue
    myLine.lineWidth = 4
    addChild(myLine)
}
func drawSemi(){
// for semi circle

    let bezierPath = UIBezierPath(arcCenter: CGPoint(x: 0, y: 0), radius: 50, startAngle: 0, endAngle: .pi, clockwise: true)
    
    let pathNode = SKShapeNode(path: bezierPath.cgPath)
    
    pathNode.strokeColor = SKColor.blue
    
    pathNode.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
    
    
    pathNode.lineWidth = 3
    
    
    
    addChild(pathNode)
}
func drawCompleteSemi(){
    drawSemi()
    drawLine(from: CGPoint(x: 450, y: 500), to: CGPoint(x: 550, y: 500))
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如荒岛 2025-01-28 19:13:24

只需在您的bezier路径上调用collect(),然后完全省略drawline函数

let bezierPath = UIBezierPath(arcCenter: CGPoint(x: 0, y: 0), radius: 50, startAngle: 0, endAngle: .pi, clockwise: true)
bezierPath.close() //<-- add this line

simply call close() on your bezier path, and omit the drawline function entirely

let bezierPath = UIBezierPath(arcCenter: CGPoint(x: 0, y: 0), radius: 50, startAngle: 0, endAngle: .pi, clockwise: true)
bezierPath.close() //<-- add this line
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文