add animation to layer's path in cocos2d

Posted by greg rock on Stack Overflow See other posts from Stack Overflow or by greg rock
Published on 2012-04-10T17:25:29Z Indexed on 2012/04/10 17:29 UTC
Read the original article Hit count: 426

Filed under:
|
|
|
|

so i'm on cocos2d but before I was on a normal ios app and I had this code :

-(void)viewDidLoad{
rootLayer = [[CALayer alloc] init];
[imageView.layer addSublayer:rootLayer];
roundPath = CGPathCreateMutable();

CGPathMoveToPoint(roundPath, nil, center.x , center.y - 35);
CGPathAddArcToPoint(roundPath, nil, center.x + 35, center.y - 35, center.x + 35, center.y + 35, 35);
CGPathAddArcToPoint(roundPath, nil, center.x + 35, center.y + 35, center.x - 35, center.y + 35, 35);
CGPathAddArcToPoint(roundPath, nil, center.x - 35, center.y + 35, center.x - 35, center.y, 35);
CGPathAddArcToPoint(roundPath, nil, center.x - 35, center.y - 35, center.x, center.y - 35, 35);

CGPathCloseSubpath(roundPath);


//Box Path

boxPath = CGPathCreateMutable();

CGPathMoveToPoint(boxPath, nil, center.x , center.y - 35);
CGPathAddArcToPoint(boxPath, nil, center.x + 35, center.y - 35, center.x + 35, center.y + 35, 4.7);
CGPathAddArcToPoint(boxPath, nil, center.x + 35, center.y + 35, center.x - 35, center.y + 35, 4.7);
CGPathAddArcToPoint(boxPath, nil, center.x - 35, center.y + 35, center.x - 35, center.y, 4.7);
CGPathAddArcToPoint(boxPath, nil, center.x - 35, center.y - 35, center.x, center.y - 35, 4.7);

CGPathCloseSubpath(boxPath);
shapeLayer = [CAShapeLayer layer];

shapeLayer.path = boxPath;

[rootLayer addSublayer:shapeLayer];

}

-(void)startAnimation

{

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];



animation.duration = 2.0;

animation.repeatCount = HUGE_VALF;

animation.autoreverses = YES;

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

animation.fromValue = (id)boxPath;

animation.toValue = (id)roundPath;


[shapeLayer addAnimation:animation forKey:@"animatePath"];

}

But I didn't found a way to do the animation fromboxpath toroundpath on cocos2d, I don't know what CCAction use . Can anybody help me ? sorry for my english I'm french :/

© Stack Overflow or respective owner

Related posts about iphone

Related posts about xcode