用底线绘制半圆圈将其用作SpriteKit中的Skshapenode
我想用底线绘制一个半圆圈,然后再次将其重用为形状节点。我该如何实施。这是我的半圈代码。 而且对某些代码进行了硬编码,因此对一些帮助表示赞赏。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在您的bezier路径上调用
collect()
,然后完全省略drawline函数simply call
close()
on your bezier path, and omit the drawline function entirely