Waffeln
Waffeln

Reputation: 213

Point or Location on UIBezierPath

I have two Circles in my game. The Circles have different sizes. Every Circle has a UIBezierPath. Now i want my Object, that is moving on one Circle, move to the other Circle to the exact same position.

enter image description here

How can i determine the position of my object on the circle or UIBezierPath and put the object to the new point on the other Path?

Path:

let Path0 = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 + yCircleOffset), radius: actualCircle.size.height / 2, startAngle: radian, endAngle: radian + CGFloat(M_PI * 4), clockwise: true)

Action:

Object1.runAction(SKAction.repeatActionForever(SKAction.followPath(Path0.CGPath, asOffset: false, orientToPath: true, speed: 100)))

Upvotes: 1

Views: 478

Answers (1)

beyowulf
beyowulf

Reputation: 15331

Can't you say something like:

func outerX(innerPoint:CGPoint)->CGFloat
{
    return (innerPoint.x-self.frame.size.width*0.5)*radius2/radius1 +self.frame.size.width*0.5
}

func outerY(innerPoint:CGPoint)->CGFloat
{
    return (innerPoint.y-self.frame.size.height*0.5)*radius2/radius1+self.frame.size.height*0.5
}

func moveObjectToOuterCircle()
{
    let innerPoint = object1.position
    let outerPoint = CGPointMake(outerX(innerPoint), outerY(innerPoint))

    object1.removeAllActions()

    object1.runAction(SKAction.moveTo(outerPoint,duration:0.25))
}

?

Upvotes: 1

Related Questions