21, Cocos2dx 3.0 game development to find small three Cocos2d-x animation and scene Effects

Source: Internet
Author: User

 

Cocos2d-x, the 2D engine, has been trying to reduce the difficulty of game development, and does not use such as 3D and vector means to achieve complex animation effect, but introduces Frame Animation to express some actions (Action) special effects that are hard to implement.
Frame Animation is similar to the music video we normally play. The engine plays the edited animation frame by frame and presents it in the game. We can edit any special effect as an animation. Therefore, theoretically, Frame Animation can achieve any effect.
Frame Animation is similar to film. A coherent animation is actually composed of many independent images in chronological order. The animation frame refers to each picture displayed. When playing an animation, the switching speed between images is extremely fast. The displayed effect is a dynamic animation effect. The animation content is arbitrary, so it can show any dynamic effect without any overhead.
In general, we can use animations to implement complex dynamic effects that cannot be done by Cocos2d-x. For example, <look for John> the animation of the protagonist in the game:

Generally, simple animations can be made using Flash tools, while more complex and delicate animations can be rendered frame by frame using 3D modeling software or completely manually drawn. Because the final output file package of the animation contains the image content of each frame, the size is relatively large, which puts a lot of pressure on memory and video memory. Considering the production cost and playback cost, if not necessary, we generally do not use a large scale of animation in the game.
The genie can be used to display a static image. To Display Dynamic images, we need to constantly switch the content displayed by the genie. Once we understand this, we can use the timer to constantly change the display content of the genie and change the static genie into an animated player. In fact, the animation provided by the Cocos2d-x is based on this principle.
An animation consists of frames. In the simplest case, each frame is a texture. We can use a texture sequence to create an animation. However, when drawing a video card, switching between textures is a costly operation, because the genie can display part of the texture, therefore, it is usually more efficient to arrange the multiple textures used by the animation in a certain order and place them under the same texture. When creating an animation, we need not only to specify the texture used by the animation, but also to specify which part of the texture is used for each frame.
The Cocos2d-x provides frame-class SpriteFrame to easily record texture display information. A frame contains two attributes: texture and region. Texture refers to the texture to be displayed, and area refers to the texture to be displayed. A frame can fully describe the content displayed by the Genie. Therefore, in an animation, frame is used to represent the content of each frame.
The animation frame class AnimationFrame also contains two attributes: one is to reference a frame, and the other is the Frame delay. An Animation class of a Cocos2d-x is an Animation description that contains the Animation frames needed to display the Animation. For frame animations that are played at a constant speed, you only need to set the same latency for all frames.
We use Animation to describe an Animation, while the sprite displays the Animation action as an Animation object. An animation is an animation action that is created by an animation object and executed by the genie. The relationship between an animation and an animation is the same as that between a CD player and a CD player. The former records the animation content, while the latter plays an animation. We do not need to repeat these classes one by one.
Let's take a look at the example of moving the main character. In this example, we continue to use the picture we have shown as an animation resource. This picture consists of four small pictures, each small image is in an independent State. For ease of use, the width and height of each image are the same: code:

In actual development, Frame Animation files are usually generated by tools. Before generating a frame animation texture, You need to possess the image resources of each frame. These resources are packaged into a large texture using tools similar to TexturePacker, and then added to the frame animation.
You can use the replaceScene method provided by ctor to conveniently switch the current scenario to another scenario. However, the scenario switching of the replaceScene method is not much modified. It only stops the current scenario and then plays back the next scenario. Scenario switching sometimes seems rigid and monotonous. In order to solve this problem, Cocos2d-x provides us with a lot of scenario switching special effects, including switching scenes show flip, wave and other gorgeous special effects, these effects are implemented through the special effect class TransitionScene.
TransitionScene is derived from CCScene. In other words, scene effects are also a scenario. The effect is similar to the compound action. A compound action is a special action that contains other actions, the included actions are also executed in certain ways;
Scenario effects are a special type of scenario. They include another scenario. When running a scenario special effect, the included original scenario will be displayed by adding a special effect. Therefore, the use of special effects is similar to that of compound actions. First, create a scenario called the original scenario. Then, use the original scenario as a parameter to create a special effect scenario. You only need to pass the special effect scenario into Director's replaceScene method. The relevant code is as follows:

Director::getInstance()->replaceScene (TransitionFlipX::create(3, pScene));

Code for all scenario effects is located in the cocos/2d/CCTransition. h (cpp) file in the Engine Directory. For more information, see scenario switching. Common scenario features:
When we add animations and special scene effects to the game, the whole game has become vivid;
To sum up, the new term SpriteFrame contains a rectangular area in the texture and texture, indicating a part of the texture. The content displayed by a genie can be represented by frame, and the frame is also the basic element of the frame animation.
Animation frame: it consists of frame frames and unit latencies. It can represent a frame in a variable speed animation. Generally, the Unit delay of a uniform animation is 1.
Animation: an Animation frame that represents the content of an Animation.
Animation action: the animation player, which is created with an animation object and can only act on the genie. To play an animation, you usually create an animation frame or frame first, then use them to create an animation, then use the animation to create an animation action, and assign a genie to execute this action.
Scenario special effects (TransitionScene): a special type of scenario can be encapsulated to implement gorgeous scenario switching special effects such as special page turning and ripple.
Haomeng master friendship reminder: When the static frame motion, Mona Lisa will smile ,,,

Related Article

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.