Cocos2d-x personal notes 2048 (2)

Source: Internet
Author: User


My own claw machine has a resolution of 480*854, ...... The notebook is 768 High.


So:

eglView->setViewName("2048");    eglView->setFrameSize(240, 427);

The window is halved to facilitate debugging.


Appdelegate. cpp is the cocos2d entry.

pDirector->setDisplayStats(false);

Whether to enable FPS. This parameter can be set to true, and disabled by false when published later.


CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480,854,kResolutionShowAll);

In addition, you can perform auto scaling on devices not 480*854.


Myscene. H I added the following:

Void menucall_start (ccobject * psender); // start the Action Void menucall_thend (ccobject * psender); // exit the action ccsize size; // screen size


All content of myscene. cpp:

# Include "myscene. H" # include "2048scene. H" // to start a game, enter myscene: myscene (void) {} myscene ::~ Myscene (void) {} ccscene * myscene: Scene () {// 'Scene 'is an autorelease object ccscene * scene = ccscene: Create (); // 'player' is an autorelease object myscene * layer = myscene: Create (); // Add layer as a child to scene-> addchild (layer ); // return the scene return scene;} bool myscene: Init () {// ccsize size = ccdirector: shareddire()-> getwinsize (); // obtain the screen size // size = ccdirector: shareddire()-> getwinsize (); size. width = 480, size. height = 854; // manually set ccsprite * homepage = ccsprite: Create ("homepage.png"); homepage-> setposition (CCP (size. width/2, size. height * 0.5); this-> addchild (homepage); // ccsprite * BG = ccsprite: Create ("helloworld.png "); // BG-> setposition (CCP (size. width/2, size. height/2); // CCP = ccpoint // This-> addchild (BG);/* ccsprite * sp0 = ccsprite: Create ("icon.png "); sp0-> setposition (CCP (100,100); this-> addchild (sp0); * // * ccsprite * SP1 = ccsprite: Create ("closenormal.png "); SP1-> setposition (CCP (100,100); BG-> addchild (SP1); * // * ccsprite * SP1 = ccsprite: Create ("icon.png "); SP1-> setposition (CCP (size. width * 0.2, size. height * 0.7); this-> addchild (SP1); ccsprite * SP2 = ccsprite: Create ("icon.png", ccrect (28,28, 29,29); // coordinates, long, wide SP2-> setposition (CCP (size. width * 0.4, size. height * 0.7); this-> addchild (SP2); cctexture2d * texture = cctexturecache: sharedtexturecache ()-> addimage ("icon.png "); // create a 2D Texture ccsprite * SP3 = ccsprite: createwithtexture (texture); SP3-> setposition (CCP (size. width * 0.6, size. height * 0.7); this-> addchild (SP3); ccsprite * SP4 = ccsprite: createwithtexture (texture, ccrect (0, 40, 40 )); SP4-> setposition (CCP (size. width * 0.8, size. height * 0.7); this-> addchild (SP4); ccspriteframe * frame = ccspriteframe: Create ("icon.png", ccrect (0, 0, 57,57 )); // cache frame ccsprite * SP5 = ccsprite: createwithspriteframe (FRAME); SP5-> setposition (CCP (size. width * 0.3, size. height * 0.3); this-> addchild (SP5); // SP5-> setscale (2); // double the size of the image. // SP5-> setscale (0.5 ); // zoom in half // SP5-> setrotation (30); // rotate 30 degrees clockwise // SP5-> setrotation (-30 ); // rotate 30 degrees counterclockwise // SP5-> setskewx (30); // tilt 30 degrees horizontally clockwise // SP5-> setskewx (-30 ); // horizontal clockwise tilt 30 degrees // SP5-> setvisible (false); // visible/SP5-> setcolor (ccc3 (255, 0, 0 )); // set the color // SP5-> setopacity (30); // Transparency 0-255 opacity // SP5-> settexture (cctexturecache: sharedtexturecache () -> addimage ("closenormal.png"); // you can change the displayed image. // You can also cache frames by using IMG. plist * // * cclabelttf * laber1 = cclabelttf: Create ("fuck", "la", 25); laber1-> setposition (CCP (size. width/2, size. height * 0.7); laber1-> setcolor (ccc3 (255,255, 0); this-> addchild (laber1); * // text/* cclabelttf * laber1 = cclabelttf:: Create ("START", "consola", 50); ccmenuitemlabel * Item1 = ccmenuitemlabel: Create (laber1, this, menu_selector (myscene: menucall_start )); item1-> setposition (CCP (size. width/2, size. height * 0.7); */ccmenuitemimage * item_start = ccmenuitemimage: Create ("start-normal.png", "start-select.png", this, menu_selector (myscene: menucall_start )); item_start-> setposition (CCP (size. width/2, size. height * 0.5); ccmenuitemimage * item_thend = ccmenuitemimage: Create ("thend-normal.png", "thend-select.png", this, menu_selector (myscene: menucall_thend )); item_thend-> setposition (CCP (size. width/2, size. height * 0.3); ccmenu * menu = ccmenu: Create (item_start, item_thend, null); menu-> setposition (ccpointzero); this-> addchild (menu ); cclabelttf * My = cclabelttf: Create ("[email protected]", "fonts/fznht. TTF ", 40); my-> setposition (CCP (size. width/2, size. height/10); this-> addchild (my); Return true;} void myscene: menucall_start (ccobject * psender) {// system ("pause "); ccscene * temps = my2048scene: Scene (); ccdirector: shareddirector ()-> replacescene (temps);} void myscene: menucall_thend (ccobject * psender) {// system ("pause"); # If (cc_target_platform = cc_platform_winrt) | (cc_target_platform = cc_platform_wp8) ccmessagebox ("you pressed the close button. windows Store apps do not implement a close button. "," alert "); # else ccdirector: shareddire()-> end (); # If (cc_target_platform = cc_platform_ios) Exit (0); # endif}

Because 2048 scene has not been written, comment out # include "2048scene. H"

There is also content in the menucall_start function.


There are also five images in one font.


Homepage.png, start-normal.png, start-select.png, thend-normal.png, thend-select.png, fznht. TTF


The background image is 480*854, and the other four are 250*150, respectively, before and after the selected image. Font effect.

Baidu: http://pan.baidu.com/s/1sjmDyhf



Cocos2d-x personal notes 2048 (2)

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.