所以我在 cocos2d 上,但在我使用普通的 ios 应用程序之前,我有这个代码:
-(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"];
}
但是我没有找到在 cocos2d 上做动画的方法boxpath
,roundpath
我不知道 CCAction 使用什么。有谁能够帮助我 ?对不起我的英语我是法国人:/