[Cocos2d-x 2.0 + Game Development] animation creation

Source: Internet
Author: User

reprint. Reprinted please note softboy
blog: http://www.softboy.uqc.cn

The first development of cocos2d-x game. While learning progress again, recorded as a blog welcome everyone to analyze.
When I develop a beautiful game, looking back, it will be a wonderful memory.
Note, this tutorial is cocos2d-2.0-rc2-x-2.0.1 compared with the previous great changes, the previous version of the tutorial is really only for reference. This is animation initialization. My figure is 500*200.
Ccanimation * animationmanager: seconds () {cctexture2d * playerruntexture = cctexturecache: seconds ()-> addimage ("seconds"); ccanimation * animation = ccanimation: Create (); for (INT I = 0; I <5; I ++) {animation-> addspriteframe (ccspriteframe: Create (playerruntexture, cocos2d: ccrectmake (100 * I, 0,100,100) ;}for (INT I = 0; I <5; I ++) {animation-> addspriteframe (ccspriteframe: Create (playerruntexture, cocos2d :: ccrectmake (100 * I, 100,100,100);} // shocould last 2.8 seconds. and there are 14 frames. animation-> setdelayperunit (0.2f); animation-> setrestoreoriginalframe (true); Return animation ;}


At this time, you can use the followingCodeLoad the animation to Hello world.

 ccsprite * m_grossini; m_grossini = ccsprite: Create ("npc.png"); m_grossini-> setposition (ccpointmake (100,100 )); addchild (m_grossini, 1); m_grossini-> setvisible (true); m_grossini-> retain (); ccanimate * Action = sanimationmgr-> createanimate ("1"); // ccanimate:: Create (sanimationmgr-> createanimate ("1"); m_grossini-> runaction (ccsequence: Create (action, action-> reverse (), null )); 


name-based animation management. to facilitate animation management.

generally, an animation is added to ccanimationcache. ccanimationcache: sharedanimationcache ()-> addanimation (createnpcanimation (), "1 ");

, use the animation each time. ccanimation * anim = ccanimationcache: sharedanimationcache ()-> animationbyname (key );
. the running graph will not be available.

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.