Size visibleSize = Director::getInstance()->getVisibleSize();
auto label = LabelTTF::create("zhangwei", "Courier", 30);
label->setPosition(Point(visibleSize.width / 2, visibleSize.height / 2));
this->addChild(label);
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [label](Touch *t, Event *e){
if (label->cocos2d::Node::getBoundingBox().containsPoint(t->getLocation()))
{//cocos2d::Node:: 这个不能省略
label->runAction(MoveTo::create(1, Point(100, 100)));
}
return false;
};
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, label);
getBoundingBox()前要加cocos2d::Node::
这句可以换成 e->getCurrentTarget()->cocos2d::Node::getBoundingBox().containsPoint(t->getLocation())