01 // CCSprite
02
03 // release all loaded images so far
04 CCTextureCache: sharedTextureCache ()-> removeAllTextures ();
05 // load the image
06 CCSprite * sprite = CCSprite: spriteWithFile ("yy.png", CCRectMake (112*0, 64*0,112, 64 ));
07 // stop all animations
08 sprite-> stopAllActions ();
09 // start the animation
10 sprite-> runAction (animate );
11 // play once
12 sprite-> runAction (CCRepeat: actionWithAction (_ animate_go, 1 ));
13 // Replay
14 sprite-> runAction (CCRepeatForever: actionWithAction (_ animate_go ));
15
16 CCAnimate * animate;
17 aimate-> stop (); // stop the animation
18
19
20 // delayed call
21 CCFiniteTimeAction * action1 = CCMoveBy: actionWithDuration (1.0f, ccp (200,200 ));
22 CCFiniteTimeAction * action2 = action1-> reverse ();
23 sprite-> runAction (CCSequence: actions (action1, CCDelayTime: actionWithDuration (1.0f), action2, NULL ));
24
25 www.2cto.com
26 // function call CCCallFunc
27 void YY: Hello ()
28 {
29 CCLog ("Hello, this your world! \ N ");
30}
31
32 void YY: Action ()
33 {
34 sprite-> stopAllActions ();
35 CCSpriteFrameCache * sfcache = CCSpriteFrameCache: sharedSpriteFrameCache ();
36 sfcache-> addSpriteFramesWithFile ("yy/yy. plist ");
37 CCMutableArray <CCSpriteFrame *> * anim_frames = new CCMutableArray <CCSpriteFrame *> ();
38 char tmp [50];
39 for (int j = 0; j <6; j ++)
40 {
41 sprintf (tmp, "yy_0000d.png", j );
42 CCSpriteFrame * frame = sfcache-> spriteFrameByName (tmp );
43 anim_frames-> addObject (frame );
44}
45
46 CCAnimation * animation = CCAnimation: animationWithFrames (anim_frames, 0.1f );
47 anim_frames-> release ();
48
49 CCAnimate * animate = CCAnimate: actionWithAnimation (animation, false );
50 CCFiniteTimeAction * action = CCCallFunc: actionWithTarget (CCObject *) this, callfunc_selector (YY: Hello ));
51 sprite-> runAction (CCSequence: actions (animate, action, NULL ));
52}
Author: Yu