Path animation with CGPathAddArcToPoint
Path animation with CGPathAddArcToPoint
- Subject: Path animation with CGPathAddArcToPoint
- From: "Gordon Hughes" <email@hidden>
- Date: Fri, 29 Aug 2008 09:57:35 -0400
In my attempts to animate objects along a circular/elliptical path, I
naturally turned to CGPathAddEllipseToPoint. Imagine a clock face with four
equidistant objects located on the path; I want the objects to animate 360
degrees from their start points. Using the elliptical path, all four
objects consistently move to the 3 o'clock position, and rotate around the
path all stacked together before jumping back to their starting positions.
When I then used CGPathAddArc, it behaved the same way - always starting at
the 3 o'clock position. I'm guessing that both methods start and end the
path at that same position.
To get around this, I tried CGPathAddArcToPoint. I know the path is being
laid out correctly, because when I draw it in a context, I get a perfect
circle. I know that all my objects are sitting on the path, because I
verified this with CGPathContainsPoint.
In the case of CGPathAddEllipseToPoint and CGPathAddArc is there any way to
move the starting position of the ellipse/arc to a user-defined point?
The offending code from my CGPathAddArcToPoint implementation is below.
Like I said, it draws a perfect circle, but I can't animate along it. If I
replace the arcs with a single elliptical path, the animation works, but
from the wrong starting points.
Thanks in advance.
Gordon
CGPoint arc[8] =
{
CGPointMake(200.0, 300.0),
CGPointMake(300.0, 300.0),
CGPointMake(300.0, 200.0),
CGPointMake(300.0, 100.0),
CGPointMake(200.0, 100.0),
CGPointMake(100.0, 100.0),
CGPointMake(100.0, 200.0),
CGPointMake(100.0, 300.0),
};
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath, NULL, arc[0].x, arc[0].y);
CGPathAddArcToPoint(thePath, NULL, arc[1].x, arc[1].y, arc[2].x, arc[2].y,
100.0);
CGPathAddArcToPoint(thePath, NULL, arc[3].x, arc[3].y, arc[4].x, arc[4].y,
100.0);
CGPathAddArcToPoint(thePath, NULL, arc[5].x, arc[5].y, arc[6].x, arc[6].y,
100.0);
CGPathAddArcToPoint(thePath, NULL, arc[7].x, arc[7].y, arc[0].x, arc[0].y,
100.0);
CGPathCloseSubpath(thePath);
CAKeyframeAnimation *followPath = [CAKeyframeAnimation animationWithKeyPath:
@"position"];
followPath.path = thePath;
followPath.delegate = self;
followPath.duration = animationDuration;
followPath.calculationMode = kCAAnimationPaced;
followPath.timingFunction = [CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut];
return followPath;
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden