Cocos2d-x CCAnimate animation playback time frame Problem

Source: Internet
Author: User

What is the frame buffer pool? What is the animation buffer pool? How do I play an animation frame by time frame? What if the interval between adjacent animation frames is different from the cocos2d-x? It's easy to use other plist files to initialize the animation buffer pool, but you have to study the source code first to solve the first problem. CCSpriteFrameCache. It uses a CCDictionary (m_pSpriteFrames) to store many CCSpriteFrame objects. The key is read from plist. Note that the default name corresponds to the name of each image contained in textures, which may contain a suffix. Therefore, I do not like this key very much. cocostudio is recommended to add the key modification function later. What is CCSpriteFrame? It is used to specify the location information in the corresponding texture map of the frame. In fact, it is not suitable to describe it as a Cache. At best, it is a packaged container. However, since people name it like this, I think it is possible to expand some later stages to use LRU or other algorithms to clear unused SpriteFrame. Other functions in CCSpriteFrameCache are used to parse plist files. Solve the second problem. CCAnimationCache. It is also a CCDictionary (m_pAnimations) that stores a lot of CCAnimation (CCAnimationFrame) objects. Now that we have a CCSpriteFrame object, why do we need another CCAnimationFrame object? If you only use CCSpriteFrame, where do you store the time slice information of each frame? Why not put the time slice information in CCSpriteFrame? The cocos2d-x is designed very well here. In case that you need multiple playing time slices for the same frame, this situation is perfectly solved. Note that the initialization function bool initWithSpriteFrame of CCAnimationFrame (CCSpriteFrame * spriteFrame, float delayUnits, CCDictionary * userInfo); the second parameter delayUnits. It is not a time. The original article explains how many units of time the frame takes. Because the COCOS2D-X's CCActionInterval playing principle is to divide a sequence of animation into animation frames with the same time slice. If the adjacent animation frame time is different, different delayUnits are allocated. We place a sequence (for example, a sequence of 8 or 10 frames in a certain direction of a role in the game) into a CCArray and create a CCAnimation, in this way, the sequence animation frame in this direction initializes an object. Here we need to explain the CCAnimation * create (CCArray * arrayOfAnimationFrameNames, float delayPerUnit, unsigned int loops) of CCAnimation. The delayPerUnit of this function is the concept of time slice. It is a time in seconds. It's too early to call CCAnimationCache. However, I believe the official team will add scaling information later. Solve the third problem. Start with CCActionInterval: step (float dt. The dt parameter is the time difference between the last call of this function and the current call of this function. The Unit is seconds. The CCActionInterval video sequence animation is played in units of time slices. The time slice here is the value that is included when CCAnimation is created. When you understand this, I am afraid you will understand why the function contains this-> update (MAX (0, MIN (1, m_elapsed/MAX (m_fDuration, FLT_EPSILON ))) let the CCAnimate execute the update operation. As for the last problem, you only need to assign the number of time slices to each CCAnimationFrame to complete the playback requirements for different frames at different times.

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.