码迷,mamicode.com
首页 > 其他好文 > 详细

cocos3 多点触控 经过真机测试

时间:2015-04-22 20:31:19      阅读:109      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!