Cocos2d-x (CCSprite)

Source: Internet
Author: User

 

 


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

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.