[cocos2d-x3.3]cocostudio的Button按钮触发两次回调函数问题解决

[cocos2d-x3.3]cocostudio的Button按钮触发两次回调函数问题解决,第1张

概述上周刚刚入职一家手游公司,应主管大神的要求开始编辑页面ui,在添加button时发现一个问题,第一次button按钮,回调一次添加函数,但是之后就会点击一次回调两次, 问题在有,ui中的按钮将button事件集成了,点击按钮会执行 集成下的事件 解决方案就是为按钮的事件添加事件类型的选择 代码如下: auto rootNode = CSLoader::createNode("MainScen

上周刚刚入职一家手游公司,应主管大神的要求开始编辑页面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 >msg_toast_bg-><span >runAction</span>(<span >Moveto</span>::<span >create</span>(<span >2</span>,<span >Point</span>(<span >320</span>,<span >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);      }
总结

以上是内存溢出为你收集整理的[cocos2d-x3.3]cocostudio的Button按钮触发两次回调函数问题解决全部内容,希望文章能够帮你解决[cocos2d-x3.3]cocostudio的Button按钮触发两次回调函数问题解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1007294.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存