Cocos2d-x homemade tool 01: AnimatePacker Beta Release !!~!

Source: Internet
Author: User

 

  I. IntroductionOh, okay, I 've been talking about the animation Loading Method of the cocos2d-x, remember what I wrote in "cocos2d-x Study Notes 04: simple animation", a simple animation loading, you need to write more than a dozen lines of code.
 
 
  1. CCSize s = CCDirector: sharedDirector ()-> getWinSize ();
  2.  
  3. // #1: Data class required for generating an animation
  4. CCTexture2D * texture = CCTextureCache: sharedTextureCache ()-> addImage ("pic2476.png ");
  5. CCSpriteFrame * frame0 = CCSpriteFrame: frameWithTexture (texture, CCRectMake (32*0, 48*0, 32, 48 ));
  6. CCSpriteFrame * frame1 = CCSpriteFrame: frameWithTexture (texture, CCRectMake (32*1, 48*0, 32, 48 ));
  7. CCSpriteFrame * frame2 = CCSpriteFrame: frameWithTexture (texture, CCRectMake (32*2, 48*0, 32, 48 ));
  8. CCSpriteFrame * frame3 = CCSpriteFrame: frameWithTexture (texture, CCRectMake (32*3, 48*0, 32, 48 ));
  9.  
  10. CCMutableArray <CCSpriteFrame *> * animFrames = new CCMutableArray <CCSpriteFrame *> (4 );
  11. AnimFrames-> addObject (frame0 );
  12. AnimFrames-> addObject (frame1 );
  13. AnimFrames-> addObject (frame2 );
  14. AnimFrames-> addObject (frame3 );
  15.  
  16. CCAnimation * animation = CCAnimation: animationWithFrames (animFrames, 0.2f );
  17. AnimFrames-> release ();
  18. // #2: Initialize and set Sprite
  19. CCSprite * sprite = CCSprite: spriteWithSpriteFrame (frame0); // you can specify an initial frame.
  20. Sprite-> setPosition (ccp (s. width/2, s. height/2 ));
  21. AddChild (sprite );
  22.  
  23. // #3: Use animation to generate an animation
  24. CCAnimate * animate = CCAnimate: actionWithAnimation (animation, false );
  25. Sprite-> runAction (CCRepeatForever: actionWithAction (animate); // Replay


Well, there are a lot of loaded code, and we can simplify it by refreshing the loop. That is to say, theoretically, at least half of the total amount can be reduced.
However, there is a premise for simplifying the brush loop: the arrangement of png must be regular, otherwise it cannot be used. In addition, different actions have different frames and different delay values. Each action must be written by yourself. This is undoubtedly a very tedious process.
So I developed an animation Acker tool to solve this problem. As the name suggests, AnimatePacker is a small tool for packaging actions, allowing you to easily edit actions by yourself. This saves a lot of program coding.
Ii. Use AnimatePacker
This tool should be used with tools such as TexturePacker because they need to provide plist. In addition, to use this tool, you must first be familiar with tools such as TexturePacker and the animation code of the cocos2d-x.
Open the interface to see at a glance. People familiar with cocos2d-x programming must know what these four boxes are.

650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201202/144050537.png "/>

Plists: All Plist lists. Drag the plist file to the AnimatePacker window to load the file. Animations: a list of all actions. Click "camera" to create a new action, and double-click it to edit Name and Delay. SpriteFrames: the list of SpriteFrames corresponding to the current Animation. You can sort them by dragging them. Sprites: All the alternative Spirte. You can drag the Spirte to the SpriteFrames box. 650) this. width = 650; "style =" cursor: default; "alt =" "src =" file: // C: /Users/goldlion/AppData/Local/Temp/enhtmlclip/image(272.16.png "/>
Simple Steps: 1. drag the plist file to the AnimatePacker window. 2. click the camera to generate a new Animation. In the Animations box, edit Name and Delay3. drag Sprite to SpriteFrames from Sprites, and drag SpriteFrame to be sorted.
In this way, you can edit and generate them continuously. Finally, click Save to output an xml file. Here we will call him "1111. xml.
Iii. Use the parsing code
To parse 1111. xml, you need to use the following three files:
 
 
  1. AnimatePacker. h
  2. AnimatePacker. cpp
  3. Singleton. h // supported files to be imported

The parsing code is very simple and there are only two interfaces:
 
 
  1. Void AnimatePacker: loadAnimate (char * path); // load the animation in xml
  2. Cocos2d: CCAnimate * AnimatePacker: getAnimate (char * name); // get the animation with the specified name

Specifically, it is written as follows:
 
 
  1. AnimatePacker::getInstance()->loadAnimate("1111.xml"); 
  2. CCSprite *sprite=CCSprite::spriteWithSpriteFrameName("bomb_dead0.png"); 
  3. sprite->setAnchorPoint(CCPointZero); 
  4. sprite->setPosition(ccp(size.width/2, size.height/2)); 
  5. sprite->runAction(CCRepeatForever::actionWithAction(AnimatePacker::getInstance()->getAnimate("aaa"))); 
  6. addChild(sprite,1); 

AnimatePacker is written in Qt, that is, it can be written across multiple platforms. However, currently only the win32 version is available, because I have not configured the qt development environment for mac, and I will provide it later. This tool is now a beta version. You are welcome to provide bugs and suggestions for improvement. Just reply below.

This article is from the "Old G hut" blog, please be sure to keep this source http://4137613.blog.51cto.com/4127613/779533

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.