Coco2d learning day01 genie Analysis

Source: Internet
Author: User
Day01 notes using namespace cocos2d; = using_ns_cc; generally, the following # ifndef _ mylayer_h __# DEFINE _ mylayer_h _ --------------- is generally added to the header file to the macro: public cclayer generally adds a class to inherit cclayer: Init (); cclabelttf * plabel = cclabelttf: Create ("Sunda", "Arial", 36 ); // define a lableaddchild (plabel, 1); // Add a lableccsize size = ccdirector: shareddirector ()-> getwinsize () to the image scene (); // obtain the current coordinate plabel-> setposition (CCP (size. width/2, size. height/2); // set the position of the lable on the stage // Add an image ccmenuitemimage: Create ("closenormal.png", "closeselected.png", this, menu_selector (mylist:: menuclosecallback); // The first vertex number is the displayed image; // The second vertex number is the image in the vertex; // The third vertex number is the fourth vertex number triggered when you click. ccmenuitemimage * inage = ccmenuitemimage: Create ("closenormal.png", "closeselected.png", this, menu_selector (mylist :: menuclosecallback); ccmenu * pmenu = ccmenu: Create (inage, null); pmenu-> setposition (); // The coordinate addchild (pmenu, 1) of the image ); // display // Add a background ccsprite * psprite = ccsprite: Create ("helloworld.png"); // Add an image psprite-> setposition (CCP (size. width/2, size. height/2); // set the position of the image addchild (psprite, 0); // return true; settouchenabled (true ); support for touch. If you do not want to write, do not approve of the settouchmode (kcctouchesallatonce); multi-point touch: for example, what is the settouchmode (kcctouchesonebyone) When both hands are pressed on the mobile phone screen: for example, what bool cctouchbegan (cctouch * ptouch, ccevent * pevent) is on the screen of a single-handed mobile phone? // void cctouchmoved (cctouch * ptouch, ccevent * pevent) when your finger is pressed ); // void cctouchended (cctouch * ptouch, ccevent * pevent) when your fingers move and press; // void cctouchcancelled (cctouch * ptouch, ccevent * pevent); // when you call, the genie creates ccsprite * sprite = ccsprite: Create ("1/furnace/jt.png "); use an image to directly create ccsprite * sprite = ccsprite: Create ("1/furnace/jt.png", ccrectmake (, 20, 20 )); // use the same image, but use some ccrectmake (the starting point of X, the starting point of Y, the end point of X, and the end point of Y) addchild (sprite ); ccsize size = ccdirector: shareddirector ()-> getwinsize (); // obtain the size of the stage sprite-> setposition (CCP (size. width/2, size. height/2); // the location where the genie is sent // texture attribute cctexture2d * texture = cctexturecache: sharedtexturecache ()-> addimage ("1/furnace/jt.png "); // create a texture, put it in the texture cache, and return the cached object ccsprite * sprite = ccsprite: createwithtexture (texture); // It is equivalent to sending the image to the memory, multiple ccsprite * sprite = ccsprite: createwithtexture (texture, ccrectmake (, 20, 20 )); // The same image is used, but some ccrectmake (the starting point of X, the starting point of Y, the end point of X, and the end point of Y) ccspriteframe * frame = ccspriteframe :: createwithtexture (texture, ccrectmake (100,100,); // The needle is part of the texture ccsprite * sprite = ccsprite: Create ("images/blocks.png "); // The URL for creating a Sprite image must be images/blocks.png addchild (sprite); sprite-> setposition (CCP (100,100); // The base point must be in the lower right corner, sprite-> setanchorpoint (CCP (0.5); // 1. The sprite's profile is (0.5,) by default and is not an absolute coordinate value, /0 is the lower right foot // is the lower left foot // scaling attribute sprite-> setscale (1.5f); // It means scaling the image sprite-> setscalex (0.5f ); // X-axis scaling sprite-> setscaley (0.5f); // y-axis scaling // rotation attribute sprite-> setrotation (90.f ); if the integer is positive, the negative number is rotated counterclockwise. Sprite-> setrotationx (90.f); Y axis is rotated by 90. degree is no sprite-> setrotationy (90.f); Y axis rotation 90. degrees are gone // distortion attributes sprite-> setskewx (601_f); X axis is distorted by 60 degrees, but up to 90 degrees, there is no sprite-> setskewy (601_f ); if the Y axis is twisted 60 degrees, but it is distorted to 90 degrees, there is no difference between rotation and distortion. If you rotate to 180 degrees and twist to 180 degrees, the rotation will change, but the distortion won't // flip sprite-> setflipx (true); is X axis flip sprite-> setflipy (true); is Y axis flip // transparent sprite-> setopacity (1 ); the range is between 0 and 255. 0 indicates full transparency, and 255 indicates opacity. // The color sprite-> setcolor (ccc3 (, 0, 0); // ccc3 (, 0 ), the numbers of records are RGB red, yellow, green // visible property sprite-> setvisible (false ); // false indicates the invisible property. // ture indicates the visible property. // specifies the sprite-> setdisplayframe (...); // extended the user data attribute. the Cocos system uses char * Buf = "helloword"; sprite-> setuserdata (BUF); char * P = (char *) sprite-> getuserdata (); cclog ("user data is % s", P); // sets the associated object sprite-> setuserobject (sprite );

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.