Cocos2d-x 2.0 animation creation (using SWF to create an animation)

Source: Internet
Author: User

Monkey original, reprinted. Reprinted Please note: Reprinted from cocos2d Development Network --cocos2dev.com, thank you!

Original address: http://www.cocos2dev.com /? P = 279

I previously introduced the creation of various animation methods for cocos2d-x, But 2.0 modified some methods, and many friends asked me how to create an animation, today I will introduce the animation creation method of 2.0, I hope you can see that you can learn how to create animations in other ways.

 

1. Use SWF to create an animation.

1. Use the TP tool to export SWF to a plist file.

2. How to create an animation:

#define kDelayPerUnit 0.08fCCActionInterval* SAAnimationManager::createRFAnimFormSwf(const char* swfName,int frames){    char str1[100] = {0};    char str2[100] = {0};    CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();    sprintf(str1, "%s.plist", swfName);    sprintf(str2, "%s.png", swfName);    cache->addSpriteFramesWithFile(str1,str2);    CCArray* animFrames = CCArray::create(15);    for(int i = 0; i < frames; i++){        sprintf(str2, "%s.swf/%04d", swfName,i);        CCSpriteFrame *frame = cache->spriteFrameByName(str2);        animFrames->addObject(frame);    }    CCAnimation *animation = CCAnimation::create(animFrames, kDelayPerUnit);    cache->removeSpriteFramesFromFile(str1);    return CCRepeatForever::create(CCAnimate::create(animation));}

Parameter introduction:

Const char * swfname: SwF name. Remember that the SWF name should be the same as that of plist. If your SWF name is different from the exported plist name, you will find that the name of each frame in the pilst is the SWF name, And the plist is your name, there will be two different names, so you will pay attention to the name when loading each frame.

Int frames: the number of frames in SWF.

 

In this way, a permanent animation is returned, and you can use a Sprite-> runaction () method to display the action.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.