Iphone 将动画添加到层';cocos2d中的s路径
所以我在cocos2d上,但在我使用普通ios应用程序之前,我有以下代码:Iphone 将动画添加到层';cocos2d中的s路径,iphone,ios,cocos2d-iphone,core-animation,cgpath,Iphone,Ios,Cocos2d Iphone,Core Animation,Cgpath,所以我在cocos2d上,但在我使用普通ios应用程序之前,我有以下代码: -(void)viewDidLoad { rootLayer = [[CALayer alloc] init]; [imageView.layer addSublayer:rootLayer]; roundPath = CGPathCreateMutable(); CGPathMoveToPoint(roundPath, nil, center.x , center.y - 35);
-(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使用了什么。有人能帮我吗?对不起,我的英语是法语://据我所知,Cocos2d中没有直接的界面来使用苹果CoreAnimation库中的CGPATH
EDIT1:对不起,我误解了你的问题!Cocos2d不提供从路径定义的一个形状到不同路径定义的另一个形状的动画/变形工具。您需要创建自己的自定义类,该类继承自CCNode,或者使用Cocos2d以外的库。如果您确实创建了自己的CCNode子类,那么现有的Cocos2d动作/动画工具可能会有用
EDIT2:如果您了解如何子类化,那么下面是一个链接,其中包含了您希望在CCNode子类中重写哪些方法的基础知识: 此外,《cocos2d编程指南》通常也会有所帮助: 如果您不了解如何子类化(例如,从现有的
类继承一个新的类
),那么我建议您使用一个更简单的问题了解面向对象编程的这一部分
我认为您最好的选择是查看CCSequence
(这是一种CCAction
)并在其中填充一系列CCMoveTo
或CCMoveBy
操作
教程链接:
但我会释放大量内存,因为根据你的想法,我可能会执行30个动作,这将是一个由30个动作组成的CCSequence。如果你担心内存问题,可以将其分解为多个序列,并将它们与CCCallFunc.ok链接起来。但我不想在路径上移动图像。我有一个路径boxpath,我喜欢将其形状修改为圆形路径。请问如何“创建从CCNode继承的自定义类?”gregrock我用“EDIT2”更新了答案以帮助您。如果我的英文措辞令人困惑,我很抱歉!