cocos2d-x 动画播放
更新:HHH   时间:2023-1-7


与动画相关的类   效果展示 TestCpp->ActionTest
CCAnimation
CCAnimate
CCAnimationCache
执行动画的三步骤
1.根据文件创建Animation
   --(1)多张图片
   --(2)一张合成图片 plist
2.根据Animation创建Animate
3.执行Animate
//1.多张分的的图片
    // Manual animation
    //
    CCAnimation* animation = CCAnimation::create();
    for( int i=1;i<15;i++)
    {
        char szName[100] = {0};
        sprintf(szName, "Images/grossini_dance_%02d.png", i);
        animation->addSpriteFrameWithFileName(szName);
    }
    // should last 2.8 seconds. And there are 14 frames.
    animation->setDelayPerUnit(2.8f / 14.0f);
    animation->setRestoreOriginalFrame(true);
    CCAnimate* action = CCAnimate::create(animation);
    m_grossini->runAction(CCSequence::create(action, action->reverse(), NULL));
    //2.plist图片加载
    // File animation
    //
    // With 2 loops and reverse
 //AnimationCache预加载的使用
    CCAnimationCache *cache = CCAnimationCache::sharedAnimationCache();
    cache->addAnimationsWithFile("animations/animations-2.plist");
    CCAnimation *animation2 = cache->animationByName("dance_1");
    CCAnimate* action2 = CCAnimate::create(animation2);
    m_tamara->runAction(CCSequence::create(action2, action2->reverse(), NULL));
AnimationCache预加载的使用

//学习如何使用工具

拼图工具:

TexturePacker

Zwoptex

骨骼动画:

cocosbuilder

cocostudio

红孩儿


返回游戏开发教程...