Reputation: 213
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.
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
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