bool MyTouchEvent1::init(){if (!Layer::init()){return false;}Size visibleSize = Director::getInstance()->getVisibleSize();Vec2 origin = Director::getInstance()->getVisibleOrigin();Sprite * sp1 = Sprite::create("HelloWorld.png");sp1->setPosition(Point(visibleSize.width/2,visibleSize.height/2));this->addChild(sp1);Sprite * sp2 = Sprite::create("node.png");sp2->setPosition(Point(visibleSize.width / 2, visibleSize.height / 2));this->addChild(sp2);//创建单机屏幕的监听器auto listener = EventListenerTouchOneByOne::create();//按下事件listener->onTouchBegan = [](Touch *touch, Event * event){//注册监听事件时绑定一个node对象,取出这个node对象auto target = static_cast<Sprite*>(event->getCurrentTarget());//坐标系转换Point pos = Director::getInstance()->convertToGL(touch->getLocationInView());//判断是不是点击到了精灵if (target->getBoundingBox().containsPoint(pos)){target->setOpacity();return true;}return false;};//抬起事件listener->onTouchEnded = [](Touch *touch, Event * event){//恢复精灵的透明度auto target = static_cast<Sprite*>(event->getCurrentTarget());target->setOpacity();};//设施点击的吞没事件(设置了以后,点击重叠部分 不会影响到下一层)listener->setSwallowTouches(true);//注册监听事件_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, sp1);_eventDispatcher->addEventListenerWithSceneGraphPriority(listener->clone(), sp2);return true;}
推荐整理分享Cocos2dx单击事件优先级实例(cocos按钮点击事件),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:cocos2d schedule,cocos2d schedule,cocos2djs,cocos2dx scrollview,cocos2d schedule,cocos2dx schedule,cocos点击按钮场景跳转,cocos点击事件,内容如对您有帮助,希望把文章链接给更多的朋友!
Cocos2dx多点触摸实例 boolMyTouchEvent2::init(){if(!Layer::init()){returnfalse;}SizevisibleSize=Director::getInstance()-getVisibleSize();Vec2origin=Director::getInstance()-getVisibleOrigin();/创建3个文本标签Label*te
Bullet(Cocos2dx)之交叉编译Android,集成到cocos2dx3.x 首先将src文件夹复制到jni文件夹,没有可以新建一个新建两个文件Android.mk,Application.mkApplication.mk内容如下:APP_ABI:=armeabiarmeabi-v7axAPP_PLATFORM:=android-8APP_
【cocos2dx】Ref 到底是什么鬼? cocos2dx中所有对象都继承于Ref,或者继承于Ref和ClonableRef中就是维护了一个计数器,用于判断该继承于Ref的对象是否应该deleteclassCC_DLLRef{