views:

70

answers:

2

Hi,

I recently downloaded the sample application, GLPaint from apple. This app showed me how to implement drawing, but now I would like to animate a image over the drawn lines. Similarly to how the application "Flight Control" works, I would like to be able to draw a path for an image and then have the image animate over this path.

any ideas?

+1  A: 

Look at CAKeyframeAnimation, this allows you to set a path (which is a CGPathRef) for the animation to run along.

Joshua Weinberg
+5  A: 

you could create your path

CGMutablePathRef thePath = CGPathCreateMutable();

and then in the touchesBegan and touchesMoved add to your path

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
  UITouch *touch = [touches anyObject];
  if(touch){
    CGPoint tapPoint = [touch locationInView: self.view];
    CGPathMoveToPoint(thePath, NULL,tapPoint.x,tapPoint.y);    
  }
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
  UITouch *touch = [touches anyObject];
  if(touch){
    CGPoint tapPoint = [touch locationInView: self.view];
    CGPathAddLineToPoint(thePath, NULL,tapPoint.x,tapPoint.y);
  }
}

and on touchedEnded, as Joshua said, create a CAKeyframeAnimation and set its path to thePath and set the other properties of your animation (duration, etc) and apply it to your object

AtomRiot