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

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

问题描述

是否可以在 Cocos2d 中创建移动动画,沿特定路径运行?

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?

问候!

推荐答案

当然你可以这样做:

    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 移动曲线中的任何节点:

you can use ccBezier to move any node in curves :

现在动画部分:

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

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

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

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