Cocos2d在一个路径上移动动画 [英] Cocos2d move animation on a path

查看:843
本文介绍了Cocos2d在一个路径上移动动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在Cocos2d中创建一个移动动画,它会在一个特定的路径?



例如,如果我需要一个对象移动

解决方案

当然您可以使用:

  ccBezierConfig bezier; 
bezier.controlPoint_1 = ccp(320,0); //控制点1
bezier.controlPoint_2 = ccp(0,0); //控制点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 , 一世]]];
}
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



http://www.math.ubc.ca/~cass/gfx/bezier.html


Is it possible in Cocos2d to create a move animation that would go on a specific path?

For example, how should I do if I need an object to move on an arc or full circle?

Regards!

解决方案

Sure you can do this using :

    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];

you can use ccBezier to move any node in curves :

Now Animation Part :

    [[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];

Reference Links : http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d

http://www.math.ubc.ca/~cass/gfx/bezier.html

这篇关于Cocos2d在一个路径上移动动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆