The elves move with their fingers.

Source: Internet
Author: User



Program code:

BOOL Helloworld::init () {////////////////////////////////1. Super init first if (!    Cclayer::init ()) {return false;    } ccsize visiblesize = Ccdirector::shareddirector ()->getvisiblesize ();    Ccpoint origin = Ccdirector::shareddirector ()->getvisibleorigin (); 2.    Add a menu item with "X" image, which are clicked to quit the program//may modify it. Add a "Close" icon to exit the progress.                                        It ' s an Autorelease object ccmenuitemimage *pcloseitem = Ccmenuitemimage::create ( "Closenormal.png", "closeselected.png", th    IS, Menu_selector (Helloworld::menuclosecallback));                                Pcloseitem->setposition (CCP (origin.x + visiblesize.width-pcloseitem->getcontentsize (). WIDTH/2, ORIGIN.Y + pcloseitem->getcontentsize (). HeigHT/2));    Create menu, it's an Autorelease object ccmenu* pmenu = Ccmenu::create (Pcloseitem, NULL);    Pmenu->setposition (Ccpointzero); This->addchild (Pmenu, 1); settouchenabled (true); SP1 = ccsprite::create ("Cpp1.png"); Sp1->setscale (0.5f); sp1-    >setposition (CCP (+)); This->addchild (SP1); return true;} Touch move void helloworld::cctouchmoved (cctouch* touch, ccevent* event) {if (Iscontrol) {Ccpoint location = touch-> Getlocationinview (); location = Ccdirector::shareddirector ()->converttogl (location); Cclog ("Cctouchmoved...x:%f y:%f", location.x, LOCATION.Y);//re-set the sprite coordinate when moving float x = location.x-deltax;float y = Location.y-deltay;sp1->setposition (CCP (x, Y));}} Touch Start Click to calculate the point coordinates with the sprite coordinate difference bool Helloworld::cctouchbegan (cctouch* Touch, ccevent* event) {Ccpoint pos = sp1-> GetPosition (); Ccpoint location = Touch->getlocationinview (), location = Ccdirector::shareddirector ()-&GT;CONVERTTOGL (location) ;//openglcclog ("Cctouchbegan...x:%f y:%f", location.x, LOCATION.Y);F (location.x > 0 && location.x <960 &&location.y >0 && LOCATION.Y < 640)//Touch rectangular Area {ISC Ontrol = true;//Calculates the coordinate difference between the touch point and the sprite DeltaX = Location.x-pos.x;deltay = Location.y-pos.y;} return true;} Touch end void helloworld::cctouchended (cctouch* touch, ccevent* event) {cclog ("cctouchended ...");//iscontrol = false;} Register Touch event void Helloworld::onenter () {ccdirector* pdirector = Ccdirector::shareddirector ();pD irector-> Gettouchdispatcher ()->addtargeteddelegate (this, 0, true); Cclayer::onenter ();} void Helloworld::onexit () {ccdirector* pdirector = Ccdirector::shareddirector ();pD irector->gettouchdispatcher ()- >removedelegate (this); Cclayer::onexit ();}



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.