Cocos2d-X to achieve Valentine's Day cards

Source: Internet
Author: User

Cocos2d-X to achieve Valentine's Day cards

For Chinese Valentine's Day greeting card, I am not unfamiliar, in learning Win32 API when using Win32 API to realize Chinese Valentine's Day greeting card, this time will use Cocos2s-X to realize Chinese Valentine's Day greeting card again

If you want to know how to use the Win32 API to implement the Chinese Valentine's Day greeting card, visit my blog:

Bitmap applications (Valentine's Day cards): http://blog.csdn.net/u010105970/article/details/19613079

 

Let's get down to the truth. Let's take a look at the effect:

 

Development Environment: VS2012 + Cocos2d-X2.2.3

 

Implementation ideas:

Prepare 7 images in png format

Create a 14-Frame Animation, add 7 images in the order of image names, and add 7 images in reverse order. When playing the animation, set the number of playback times of the animation to countless times, add a music in WAV format to the resource and use SimpleAudioEngine to play the music.

 

Program code:

 

# Include Scene. h # include SimpleAudioEngine. husing namespace CocosDenshion; Scene: Scene (void) {} Scene ::~ Scene (void) {} CCScene * Scene: scene () {CCScene * scene = CCScene: create (); CCLayer * layer = Scene: create (); scene-> addChild (layer); return scene;} bool Scene: init () {CCLayer: init (); CCSize winSize = CCDirector: shareddire () -> getWinSize (); // Add the background image CCSprite * bk = CCSprite: create(IMAGE_1.png); addChild (bk); bk-> setPosition (ccp (winSize. width/2, winSize. height/2); // play the background music CocosDenshion: SimpleAudioEngine: sharedEngine ()-> playBackgroundMusic(1.wav, true ); // create a set of 7 CCArray * aniframe = CCArray: createWithCapacity (14); // genie CCSprite * sprite; char str [20]; for (int I = 1; I <= 7; I ++) {// use subscript to dynamically create sprintf (str, image_demod.png, I); CCSpriteFrame * frame = CCSpriteFrame :: create (str, CCRectMake (639,423,); if (I = 1) {// by default, the first frame is added to the interface sprite = CCSprite: createWithSpriteFrame (frame ); sprite-> setPosition (ccp (winSize. width/2, winSize. height/2); addChild (sprite);} // Add each sprite animation to the set aniframe-> addObject (frame);} for (int I = 7; i> = 1; I --) {// use subscript to dynamically create sprintf (str, image_mongod.png, I); CCSpriteFrame * frame = CCSpriteFrame: create (str, CCRectMake (0, 0, 639,423); if (I = 7) {// by default, add the first frame to the interface sprite = CCSprite: createWithSpriteFrame (frame ); sprite-> setPosition (ccp (winSize. width/2, winSize. height/2); addChild (sprite);} // Add each sprite animation to the set aniframe-> addObject (frame );} // use a set to create an animation CCAnimation * animation = CCAnimation: createWithSpriteFrames (aniframe, 0.1f); CCAnimate * animate = CCAnimate: create (animation ); // execute the animation sprite-> runAction (CCRepeatForever: create (animate); return true ;}

 

??

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.