首页 > 其他 > 详细

cocos3 多点触控 经过真机测试

时间:2015-04-22 20:30:19      阅读:315      评论:0      收藏:0      [点我收藏+]
bool HelloWorld::init()
{

    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    label=LabelTTF::create("show","Courier",50);
    label->setPosition(240,160);
    addChild(label);


    EventListenerTouchAllAtOnce* listener=EventListenerTouchAllAtOnce::create();
    
    listener->onTouchesBegan = [this](const std::vector<Touch*>& touches, Event *event) {
        for(int i=0;i<touches.size();i++)
        {
            auto touch=touches.at(i);
            poses.pushBack(touch);
        }

    };

    listener->onTouchesMoved = [this](const std::vector<Touch*>& touches, Event *event) 
    {
        
    };

    listener->onTouchesEnded = [this](const std::vector<Touch*>& touches, Event *event) 
    {
        for(int i=0;i<touches.size();i++)
        {
            auto touch=touches.at(i);
            poses.eraseObject(touch);
        }
    };

    listener->onTouchesCancelled = [this](const std::vector<Touch*>& touches, Event *event)
    {
        for(int i=0;i<touches.size();i++)
        {
            auto touch=touches.at(i);
            poses.eraseObject(touch);
        }
    };

    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
         

    scheduleUpdate();
    
    return true;
}

void HelloWorld::update(float dt)
{
    char str[10];
    sprintf(str,"%d",poses.size());
    label->setString(str);
}

 

cocos3 多点触控 经过真机测试

原文:http://www.cnblogs.com/yufenghou/p/4448435.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!