2017-02-02 5 views
0

ベジェ曲線を作成し、オブジェクトの衝突境界を作成します。私は適切な衝突を作成することはできませんように私はこの2回の試行でaddArcWithCenteベジェパスを閉じるのを防ぐにはどうすればいいですか?

line.moveToPoint(firstSurfacePoint) 
line.addArcWithCenter(center, radius: radius, startAngle: CGFloat(M_PI), endAngle: CGFloat(M_PI/2), clockwise: false) 
line.addLineToPoint(fourthSurfacePoint) 

を選択した場合、私は、取得

let firstSurfacePoint = CGPoint(x: 30, y: 120) 
let secondSurfacePoint = CGPoint(x: 20, y: 200) 
let thirdSurfacePoint = CGPoint(x: 200, y: 300) 

let center = CGPoint(x: 150, y: 120) 
let radius: CGFloat = 120.00 
let arcWidth: CGFloat = 20.00  
let fourthSurfacePoint = CGPoint(x: 240, y: 300) 

func createCollisionPath(collision: UICollisionBehavior) { 

    let line = UIBezierPath() 

    line.moveToPoint(firstSurfacePoint) 
    line.addCurveToPoint(thirdSurfacePoint, controlPoint1: secondSurfacePoint, controlPoint2: secondSurfacePoint) 
    line.addLineToPoint(fourthSurfacePoint) 

    let currentPath = CAShapeLayer() 
    currentPath.path = line.CGPath 
    currentPath.strokeColor = UIColor.blackColor().CGColor 
    currentPath.fillColor = UIColor.clearColor().CGColor 
    currentPath.lineWidth = 1 
    view.layer.addSublayer(currentPath) 

    collision.addBoundaryWithIdentifier("curve", forPath: line) 

} 

同じ貧しい結果が、重要である奇妙な結果を受け取ります。最初の試みでは、オブジェクトは、最初の点から3番目の点までの直線と同様に、パスを通ります。

何が間違っていますか?

My figure(without Arc)

My figure(with Arc)

+0

働いていたではなく、私は疑うようhttp://stackoverflow.com/q/40756457/2303865 –

答えて

0
currentPath.fillColor = nil 

または

currentPath.fillColor = UIColor.clearColor().CGColor 
+0

おかげで、。主な問題は残っています。このラインは境界線を作成しません。私のオブジェクトは、firstPointからthirdPointへの線のようにパスを通ります。 – dand1

+0

あなたはあなたの移動オブジェクトを 'UICollectionBehavior'に追加しましたか?素晴らしいチュートリアルはhttps://www.raywenderlich.com/50197/uikit-dynamics-tutorialに掲載されています – tgyhlsb

+0

あなたは私のアップデートを探してください。 – dand1

関連する問題