Cocos2d-x cainiao intern study frame-by-frame animation

Source: Internet
Author: User

Speaking of this frame-by-frame animation, the amount should be called frame-by-frame animation. It is easier to understand this product, because flash was used for six months in freshman year, so it is still easy to use. Start with the built-in tsetcpp: In actiontest, "Center: Manual animation. border: using file format animation example: the following sentence: // This is the first method: CCAnimation * animation = CCAnimation: create (); // create an animation for (int I = 1; I <15; I ++) {// There are 14 frames in total, put 14 frames into the szName array: char szName [100] = {0}; sprintf (szName, "Images/grossini_dance_10902d.png", I ); animation-> addSpriteFrameWithFileName (szName);} // shocould last 2.8 seconds. and there are 14 fram Es. animation-> setDelayPerUnit (2.8f/14.0f); animation-> setRestoreOriginalFrame (true); CCAnimate * action = CCAnimate: create (animation); m_grossini-> runAction (CCSequence :: create (action, action-> reverse (), NULL); // File animation, this is the second method // With 2 loops and reverse CCAnimationCache * cache = CCAnimationCache: sharedAnimationCache (); cache-> addAnimationsWithFile ("animations/animations-2.plis T "); CCAnimation * animation2 = cache-> animationByName (" dance_1 "); CCAnimate * action2 = CCAnimate: create (animation2); m_tamara-> runAction (CCSequence :: create (action2, action2-> reverse (), NULL); // File animation, this is the third method. In fact, this cannot be said, it makes some basic changes based on the second type. // with 4 loops CCAnimation * animation3 = (CCAnimation *) animation2-> copy () -> autorelease (); animation3-> setLoops (4); CCAnimate * action3 = CCAni Mate: create (animation3); m_kathia-> runAction (action3); well, test is like this, but what I must emphasize is: I have never used the above methods !!! First, every frame of animation appears in every corner of the scene at the same time. I am confused, and I don't know why. What's wrong with .png? Shouldn't it be? The second type is stuck in CCAnimation * animation2 = cache-> animationByName ("dance_1"); why? Because dance_1 is not an image, it is an animation, and I don't know when or where to do this animation, so I rushed to the street. The third type is similar to the second type, and there is no solution. Since none of the above methods works, I gave up test. At this very serious moment, I decided to adopt a silly frame-by-frame animation. Please refer to the large screen: CCSpriteFrameCache * cache = CCSpriteFrameCache: sharedSpriteFrameCache (); cache-> addSpriteFramesWithFile ("feng/fall. plist "); CCArray * animFrames = new CCArray (3); // a total of 4 Gbit/s CCSpriteFrame * frame = cache-> spriteFrameByName (" fall1.png "); // Add 1st bytes animFrames-> addObject (frame); frame = cache-> spriteFrameByName ("fall2.png"); // Add 2nd bytes animFrames-> addObject (frame ); frame = cache-> spriteFrameByName ("fall3.png"); // Add 3rd bytes animFrames-> addObject (frame ); // control the fall each frame of move CCAnimation * animation = CCAnimation: createWithSpriteFrames (animFrames, 0.2f); CCAnimate * action = CCAnimate: create (animation ); CCSprite * fall = CCSprite: create ("feng/fall1.png"); fall-> runAction (CCRepeatForever: create (action); this-> addChild (fall, 1 ); fall-> setAnchorPoint (CCPointZero); fall-> setPosition (ccp (215,370); fall-> setScale (0.5f );

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.