学习笔记--cocos2dx-3.0中LabelTTF添加触摸监听事件

来源:互联网 发布:php程序员是什么 编辑:程序博客网 时间:2024/04/30 21:09
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())

0 0
原创粉丝点击