• cocos2dx 多触点监听


    /首先到cocos2d-x项目下的ios文件夹下,找到AppController.mm文件,在函数 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中添加如下函数:  [__glView setMultipleTouchEnabled:YES];  
      
    bool HelloWorld::init()  
    {  
          
        if ( !CCLayer::init() )  
        {  
            return false;  
        }  
          
        //开启多触点监听务必调用此函数  
        setTouchEnabled(true);  
          
        CCSprite* sp1 = CCSprite::create("Icon.png");  
        sp1->setPosition(ccp(150, 200));  
        addChild(sp1, 0, 23);  
          
        CCSprite* sp2 = CCSprite::create("Icon.png");  
        sp2->setColor(ccc3(0, 255, 0));  
        sp2->setPosition(ccp(150, 100));  
        addChild(sp2, 0, 24);  
          
        return true;  
    }  
      
    //第一次碰触  
    void HelloWorld::ccTouchesBegan(cocos2d::CCSet *touches, cocos2d::CCEvent *event)  
    {  
        CCSetIterator inter = touches->begin();  
        for(; inter != touches->end(); inter++)  
        {  
            CCTouch* touch = (CCTouch*)(*inter);  
            CCPoint point = touch->getLocation();  
            if(touch->getID() == 0) //第一个触点  
            {  
                CCSprite* sp1 = (CCSprite*)getChildByTag(23);  
                sp1->setPosition(point);  
            }else if(touch->getID() == 1)//第二个触点  
            {  
                CCSprite* sp2 = (CCSprite*)getChildByTag(24);  
                sp2->setPosition(point);  
            }  
        }  
    }  
      
    //移动或拖拽  
    void HelloWorld::ccTouchesMoved(cocos2d::CCSet *touches, cocos2d::CCEvent *event)  
    {  
        CCSetIterator inter = touches->begin();  
        for(; inter != touches->end(); inter++)  
        {  
            CCTouch* touch = (CCTouch*) (*inter);  
            CCPoint point = touch->getLocation();  
            if(touch->getID() == 0)  
            {  
                CCSprite* sp1 = (CCSprite*)getChildByTag(23);  
                sp1->setPosition(point);  
            }else if(touch->getID() == 1)  
            {  
                CCSprite* sp2 = (CCSprite*)getChildByTag(24);  
                sp2->setPosition(point);  
            }  
        }  
    }  
      
    //用户手指抬起  
    void HelloWorld::ccTouchesEnded(cocos2d::CCSet *touches, cocos2d::CCEvent *event)  
    {  
          
    }  
      
    //多触点的委托监听注册放在onEnter的生命函数中会造成程序异常退出。默认都写在下面函数中。  
    void HelloWorld::registerWithTouchDispatche()  
    {  
        CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 0);  
    }  
      
      
    //删除多触点的委托监听  
    void HelloWorld::onExit()  
    {  
        CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);  
      
        //这句务必要写  
        CCLayer::onExit();  
    }  
  • 相关阅读:
    LDAP安装配置(windows)
    chrome postman插件手动安装
    mabatis insert into on duplicate key
    ZOJ 3641 <并查集+STL>
    ZOJ 3633 <rmq 重点在于转化>
    POJ 2817 状态DP 字符串找最多的重复
    POJ 2771 简单二分图匹配
    POJ 1149 最大流<建图> PIGS
    POJ 3692 二分图最大独立点集
    POJ 2239 简单的二分图求最大匹配
  • 原文地址:https://www.cnblogs.com/jiackyan/p/3042583.html
Copyright © 2020-2023  润新知