cocos2d loads plist files (frame animation)

Integrate the pictures into one large picture, reduce the picture occupancy, there are plist files and png supporting files.

cocos loads plist files in two ways (queried)
1. If you load in the following way, your plist file must contain an animations node, otherwise the load will fail

auto cache = AnimationCache::getInstance(); 
cache->addAnimationsWithFile("animations/animations-2.plist"); 

2. Manual addition requires orderly addition of the elves to be displayed in each frame to the Animation class and setting the playing time of each frame so that the animation can be played at a uniform speed.setRestoreOriginalFrame also sets whether to revert to the first frame after the animation has finished playing.Once you have created an Animation instance, you need to create an Animate instance to play the sequence frame animation.(excerpt from network)

    /×Note that adding a search path, if it is not the resource root directory, may not load successfully×/
    FileUtils::getInstance()->addSearchPath("Game/anamate/");
    CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
    frameCache->addSpriteFramesWithFile("Emoji.plist");e

    /×Frame by frame will png Add to Cache×/
    Vector<SpriteFrame*> animations;
    char str[100] = { 0 };
    for (int i = 1; i <= 3; i++)
    {
        sprintf(str, "1_%d.png", i);
        CCSpriteFrame *frame = frameCache->spriteFrameByName(str);
        animations.pushBack(frame);
    }
    /×Interval 0.2s,2 Subcycle×/
    cocos2d::CCAnimation* my_animation = CCAnimation::createWithSpriteFrames(animations, 0.2f, 2);
    CCAnimationCache::sharedAnimationCache()->addAnimation(my_animation, "smile");

    cocos2d::CCAnimate* my_ani = CCAnimate::create(my_animation);
    cocos2d::Sprite × my_test_sp = CCSprite::create();

#if  1
    my_test_sp->setSpriteFrame("1_1.png");
#else
    CCSpriteFrame* frame = frameCache->spriteFrameByName("1_1.png");
    my_test_sp->setDisplayFrame(frame);
#endif

    my_test_sp->setPosition(500, 500);
    addChild(my_test_sp);
    my_test_sp->runAction(Sequence::create(my_ani, CCHide::create(), nullptr));

The above is a complete load and play

But if you want to repeat the irregular activation later on (call)

    cocos2d::CCAnimate * my_ani = CCAnimate::create(my_animation);
    my_test_sp->runAction(Sequence::create(my_ani, CCHide::create(), nullptr));
    my_test_sp->setVisible(true);

Keywords: network emoji

Added by zahidraf on Tue, 30 Jun 2020 19:21:37 +0300