我试图使用Bezier Path为我的物体碰撞创建一个边界。我当然明白如何使用这种方法,但似乎我的路径建设不是应该的。
let firstSurfacePoint = CGPoint(x: 30, y: 120)
let fourthSurfacePoint = CGPoint(x: 240, y: 240)
let center = CGPoint(x: 150, y: 120)
let radius: CGFloat = 120.00
let arcWidth: CGFloat = 20.00
let line = UIBezierPath()
line.moveToPoint(self.firstSurfacePoint)
line.addArcWithCenter(self.center, radius: self.radius, startAngle: CGFloat(M_PI), endAngle: CGFloat(M_PI/2), clockwise: false)
line.addLineToPoint(self.fourthSurfacePoint)
line.addArcWithCenter(CGPoint(x: self.fourthSurfacePoint.x, y: self.fourthSurfacePoint.y-self.radius/2), radius: self.radius/2, startAngle:CGFloat(3*M_PI/2), endAngle: CGFloat(M_PI/2), clockwise: true)
line.addArcWithCenter(CGPoint(x: self.fourthSurfacePoint.x, y: self.fourthSurfacePoint.y-self.radius/2), radius: self.radius/2, startAngle: CGFloat(M_PI/2), endAngle: CGFloat(M_PI), clockwise: false)
let currentPath = CAShapeLayer()
currentPath.path = line.CGPath
currentPath.strokeColor = UIColor.blackColor().CGColor
currentPath.fillColor = UIColor.clearColor().CGColor
currentPath.lineWidth = 1
self.view.layer.addSublayer(currentPath)
collision.addBoundaryWithIdentifier("curve", forPath: line)
self.addGravity()
碰撞没有问题,但似乎我的路径从最后一点关闭回到第一部分,在它们之间创建了一条线。 我没有使用closePath()方法,所以很奇怪,为什么它是穿着路径。