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.