Cocos2d-x-3.0 alpha1 with C ++ 11 exercise 10: dart ninja, add a skeleton animation in WelcomeScene

Source: Internet
Author: User

Snail bait is going to add an animation to the WelcomeScene screen and play it automatically once it is displayed. Find the tutorials and learn these implementation skills: cocostudio supports animation and skeleton animation editing, which can be done with its AnimationEditor. In AnimationEditor, there are two modes: Form mode and Animation Mode. The former is used for regular editing, placement of components, and addition of bone points. After clicking the shape mode in the upper-right corner, you can switch to the Animation Mode. Compared to the shape mode, the Animation Mode has a timeline, similar to the Flash timeline. From the product perspective, why are there two models? Instead of letting users do everything in one mode, such as Flash? In the shape mode, there are two tool buttons bound to the skeleton: 1 is the show/hide skeleton button, which is used to switch whether the skeleton is displayed in the scene. 2. Click the create and stop create bone button. Currently, you can create a skeleton component by placing the image in the following steps: Click the start create skeleton button in the scene and click it in the form of a cross. When you press it, you can also drag it to one side. Click the create bone button to select the image, right-click the menu, select "bind to bone", and click the last created bone to complete the binding. At this time, in the object panel, we can see that the image object and the bone object have been automatically merged into one. Right-click a bone, select "bind parent", select another bone, and bind it to the upper level to add constraints. In cocostudio, after creating Armature, export it and add it to the Resources directory of xcode. Loading Armation is different from loading widgets. Cocos2d-x 3 has three layers of ArmatureDataManager, Armature, and Animation objects for loading and playing animations. Add the json file to ArmatureManager, and create the file by name. Armature is an Animation set that includes multiple Animation sets. Each Animation has a name. In AnimationEditor, there is an animation name in the animation list Panel. This name can be changed manually. It is the parameter that needs to be passed in when Armature's play method is called, to specify which animation to play. After Armature plays an Animation, it uses the Event Callback Function to know the Animation status. The callback function is defined as: movementCallback (Armature * armature, MovementEventType type, const char * name) 1. Prepare the UI to use cocostudio to create a bone animation, export it, and introduce 2 in xcode, the implementation code is in WelcomeScene. in init of cpp, add the following code before return: // first load ArmatureArmatureDataManager: getInstance ()-> addArmatureFileInfo ("NewProject1.ExportJson "); // create and add ArmatureArmature * armature = Armature: create ("NewProject1"); Size winSize = Director: getInstance ()-> getWinSize (); armatu Re-> setPosition (Point (winSize. width/2, winSize. height/2); this-> addChild (armature); // play the hit animation armature-> getAnimation ()-> destroy (this, movementEvent_selector (WelcomeScene: hitMovementCallback )); armature-> getAnimation ()-> play ("hit"); here we use an hitMovementCallback callback function, which is defined in the header file first and then implemented in the cpp file: void WelcomeScene:: hitMovementCallback (Armature * armature, MovementEventType type, const char * na Me) {printf ("movement callback name: % s \ n", name); switch (type) {case cocostudio: LOOP_COMPLETE: armature-> getAnimation () -> stop (); break; default: break;} The LOOP_COMPLETE event occurs after a playback is completed. Call the stop method of Animation to achieve the playback effect once.

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.