Cocos2d-x turning on multi-touch points

Source: Internet
Author: User
Tags bool

Hard work and perseverance.

Add delegate

Addstandarddelegate ();


Turn on multi-touch

Settouchenabled ();


Touch Screen Event:

1. Register Multi-Touch

virtual void registerwithtouchdispatcher (void);

2. callback function that responds when the user first touches the phone screen

virtual void Cctouchesbegan (Ccset * touchs,ccevent * event);

3. Response callback function when the user's finger is sliding on the phone screen

virtual void cctouchesmoved (Ccset * touchs,ccevent * event);

4. callback function that responds when the user's finger leaves the phone screen

virtual void cctouchesended (Ccset * touchs,ccevent * event);

5. Add the open multi-touch code in the appcontroller.mm Didfinishlaunchingwithoptions method. As follows:

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {//Ove

    Rride point to Customization after application launch.
    ADD The View controller ' s view to the window and display.
    window = [[UIWindow alloc] initWithFrame: [[UIScreen mainscreen] bounds]]; Eaglview *__glview = [eaglview viewwithframe: [Window bounds] Pixelformat:keaglcolor FormatRGBA8 depthformat:gl_depth_component16 PRESERVEB
                                 Ackbuffer:no Sharegroup:nil Multisampling:no
    NUMBEROFSAMPLES:0]; [__glview Setmultipletouchenabled:yes]; Add this code//use Rootviewcontroller manage Eaglview viewcontroller = [[Rootviewcontroller alloc] Initwithnibname:ni
    L Bundle:nil];
    Viewcontroller.wantsfullscreenlayout = YES; Viewcontroller.view = __glview; Set Rootviewcontroller to Window if ([[Uidevice currentdevice].systemversion Floatvalue] < 6.0) {/
    /Warning:addsubview doesn ' t work on iOS6 [window AddSubview:viewController.view];
    } else {//Use this method on IOS6 [window Setrootviewcontroller:viewcontroller];

    } [window makekeyandvisible];

    [[UIApplication sharedapplication] setstatusbarhidden:yes];
    Cocos2d::ccapplication::sharedapplication ()->run ();
return YES; }


. cpp Simple case:

#include "HelloWorldScene.h" #include "SimpleAudioEngine.h" using namespace cocos2d;

using namespace Cocosdenshion;
    ccscene* Helloworld::scene () {Ccscene *scene = Ccscene::create ();
    HelloWorld *layer = Helloworld::create ();
    Scene->addchild (layer);
return scene; } bool Helloworld::init () {if (!
    Cclayer::init ()) {return false;
    
    }//Turn on multi-touch this->settouchenabled (TRUE);
return true; }//Register multi-Touch void Helloworld::registerwithtouchdispatcher (void) {//Register monitor ccdirector::shareddirector ()->gettouchd
Ispatcher ()->addstandarddelegate (this,0);
    } void Helloworld::cctouchesbegan (Ccset *ptouches, ccevent *pevent) {Ccsetiterator it;
    
    Cctouch* Touch;  Here it is equivalent to the number of system allocations,//ptouches->begin () gets the first digit//ptouches->end () is the last for (it = Ptouches->begin (); it ! = Ptouches->end ();
        
        it++) {touch = (cctouch*) (*it);
        
        if (!touch) break; Cclog ("Began id = =%d ", Touch->getid ());
    }} void Helloworld::cctouchesmoved (Ccset *ptouches, ccevent *pevent) {Ccsetiterator it;
    
    Cctouch* Touch;
        
        for (it = Ptouches->begin (); It! = Ptouches->end (); it++) {touch = (cctouch*) (*it);
        
        if (!touch) break;
    Cclog ("Moved id = =%d", Touch->getid ());
    }} void Helloworld::cctouchesended (Ccset *ptouches, ccevent *pevent) {Ccsetiterator it;
    
    Cctouch* Touch;
        
        for (it = Ptouches->begin (); It! = Ptouches->end (); it++) {touch = (cctouch*) (*it);
        
        if (!touch) break;
    Cclog ("Ende id = =%d", Touch->getid ()); }}//write on life cycle function void Helloworld::onenter () {cclayer::onenter ();} void Helloworld::onexit () {Ccdirector::sharedd
    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.