[cocos2d-x3.3]cocostudio的Button按钮触发两次回调函数问题解决
发布时间:2020-12-14 19:17:45 所属栏目:百科 来源:网络整理
导读:上周刚刚入职一家手游公司,应主管大神的要求开始编辑页面ui,在添加button时发现一个问题,第一次button按钮,回调一次添加函数,但是之后就会点击一次回调两次, 问题在有,ui中的按钮将button事件集成了,点击按钮会执行 集成下的事件 解决方案就是为按钮
上周刚刚入职一家手游公司,应主管大神的要求开始编辑页面ui,在添加button时发现一个问题,第一次button按钮,回调一次添加函数,但是之后就会点击一次回调两次, 问题在有,ui中的按钮将button事件集成了,点击按钮会执行 集成下的事件 解决方案就是为按钮的事件添加事件类型的选择 代码如下: auto rootNode = CSLoader::createNode("MainScene.csb"); rootNode->setTag(111); addChild(rootNode);新出的cocos引擎v1.0 PreView集成下的cocostudio可以将编辑好的ui界面直接生成.csb文件并且发布到xcode工程(6以上版本) auto common_silver=static_cast<ui::Button *>(rootNode->getChildByTag(12)->getChildByTag(13)->getChildByName("Button_5")); common_silver->addTouchEventListener(this,toucheventselector(HelloWorld::touchEvent)); 获取ui中的Buttonu并且执行回调函数,参数添加事件类型选择 void touchEvent(Ref *pSender,TouchEventType type); void HelloWorld::touchEvent(Ref *pSender,TouchEventType type) { switch (type) { case TOUCH_EVENT_BEGAN://触摸开始 if (silvercount>=2000) { // auto label=(Label*)getChildByTag(111)->getChildByTag(12)->getChildByTag(13)->getChildByTag(116); count+=10; label->setString(StringUtils::format("战力提升%d%%",count)); silvercount-=2000; auto label2=(Label*)getChildByTag(111)->getChildByTag(115); label2->setString(StringUtils::format("%d",silvercount)); } else { auto msg_toast_bg=Sprite::create("res/iphone/msg_toast_bg.png"); this->addChild(msg_toast_bg); msg_toast_bg->setPosition(320,400); auto msg_toast_label=Label::createWithSystemFont("银币不够","",30); msg_toast_bg->addChild(msg_toast_label); msg_toast_label->setPosition(320,25); msg_toast_bg->runAction(MoveTo::create(2,Point(320,600))); msg_toast_bg->runAction(Sequence::create(FadeIn::create(1),FadeOut::create(0.1f ),NULL)); msg_toast_label->runAction(Sequence::create(FadeIn::create(1),NULL)); // msg_toast_bg->runAction(Sequence::create(MoveTo::create(2,600),CallFunc::create( HelloWorld::jump(),this) ),NULL)); //msg_toast_bg->runAction(Sequence::create(MoveTo::create(2,600)),CallFunc::create(this,callfunc_selector(this,(HelloWorld::jump()))),NULL)); break; } } } 循环播放一个动画 mowangb->runAction(RepeatForever::create(Sequence::create(ScaleTo::create(2,1.05),ScaleTo::create(2,1),NULL))); <p class="p1">msg_toast_bg-><span class="s1">runAction</span>(<span class="s2">MoveTo</span>::<span class="s1">create</span>(<span class="s3">2</span>,<span class="s2">Point</span>(<span class="s3">320</span>,<span class="s3">600</span>)));</p> 设置一个层的现实隐藏 panle->setVisile(false); panle->setVisible(true);循环事件 每0.05执行一边 this->schedule(schedule_selector(Helloworld::hplogic),0.05);转义字符%% label2->setString(StringUtils::format("%d",silvercount));事件的暂停与启用 if (panelGold->isVisible()){ Director::getInstance()->getEventDispatcher()->pauseEventListenersForTarget(this); }else{ Director::getInstance()->getEventDispatcher()->resumeEventListenersForTarget(this); } cocostudio中loardingbar的使用 void HelloWorld::hpLogic(float t) { hp++; CCLOG("%d",hp); if (hp>=100) { hp=0; } auto loadingBar_left_to_right=static_cast<ui::LoadingBar *>(getChildByTag(111)->getChildByName("LoadingBar_1")); loadingBar_left_to_right->setPercent(hp); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |