Cocos2d中是否可以创建一个特定路径的移动动画?
例如,如果我需要一个物体在圆弧或整圆上移动,我该怎么办?
问候!
答案 0 :(得分:10)
当然可以使用以下方式执行此操作:
ccBezierConfig bezier;
bezier.controlPoint_1 = ccp(320,0); // control point 1
bezier.controlPoint_2 =ccp(0,0); // control point 2
bezier.endPosition = ccp(endPoint.x,endPoint.y) ;
id bezierForward = [CCBezierTo actionWithDuration:3 bezier:bezier];
[ball runAction:bezierForward];
您可以使用ccBezier移动曲线中的任何节点:
现在动画部分:
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"eggAnimation.plist"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"eggAnimation.png"];
[gameBackgroundLayer addChild:spriteSheet];
eggAnimFrames = [NSMutableArray array];
for ( int i = 1; i <= 10; i++ )
{
[eggAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%d.png", i]]];
}
rotateAnim = [CCAnimation animationWithFrames:eggAnimFrames delay:0.05f];
ball = [CCSprite spriteWithSpriteFrameName:@"1.png"];
ball.position=ccp(160,80);
rotateAction =[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:rotateAnim restoreOriginalFrame:YES]];
[spriteSheet addChild:ball];
参考链接:http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d