标签:
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); }
标签:
原文地址:http://www.cnblogs.com/yufenghou/p/4448435.html