Cocos2d触摸:多点触摸

来源:互联网 发布:炫浪网络社区 - 电脑版 编辑:程序博客网 时间:2024/04/25 22:16
  1.    // 多点触摸
  2.    Size visibleSize = Director::getInstance()->getVisibleSize();
  3.    auto label = Label::createWithSystemFont("多点触摸demo", "", 24);
  4.    label->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
  5.    this->addChild(label,1,100);
  6.    auto listener = EventListenerTouchAllAtOnce::create();
  7.    listener->onTouchesBegan = [&](const std::vector<Touch*>& touchs, Event* event) {
  8.        
  9.        auto label1 = (Label*) this->getChildByTag(100);
  10.        
  11.        
  12.        for (auto &touch: touchs) {
  13.            
  14.            auto finger = touch->getID() + 1;
  15.            label1->setString( "按下去"+Value(finger).asString() + "根手指^^");
  16.        }
  17.        
  18.        
  19.    };
  20.    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

0 0